Add GetChange function to gerrit module

Change-Id: Ia3b9ad8692ce06f729e663bb26ac56f7f1db5dcd
diff --git a/gerrit/.api b/gerrit/.api
index 3f298c1..4c943bb 100644
--- a/gerrit/.api
+++ b/gerrit/.api
@@ -15,6 +15,7 @@
 pkg gerrit, func Reference(CLOpts) string
 pkg gerrit, func WriteLog(string, CLList) error
 pkg gerrit, method (*ChangeError) Error() string
+pkg gerrit, method (*Gerrit) GetChange(int) (*Change, error)
 pkg gerrit, method (*Gerrit) PostReview(string, string, map[string]string) error
 pkg gerrit, method (*Gerrit) Query(string) (CLList, error)
 pkg gerrit, method (*Gerrit) SetTopic(string, CLOpts) error
diff --git a/gerrit/gerrit.go b/gerrit/gerrit.go
index 40eb37d..874e5be 100644
--- a/gerrit/gerrit.go
+++ b/gerrit/gerrit.go
@@ -363,6 +363,23 @@
 	return parseQueryResults(res.Body)
 }
 
+// GetChange returns a Change object for the given changeId number.
+func (g *Gerrit) GetChange(changeNumber int) (*Change, error) {
+	clList, err := g.Query(fmt.Sprintf("%d", changeNumber))
+	if err != nil {
+		return nil, err
+	}
+	if len(clList) == 0 {
+		return nil, fmt.Errorf("Query for change '%d' returned no results", changeNumber)
+	}
+	if len(clList) > 1 {
+		// Based on cursory testing with Gerrit, I don't expect this to ever happen, but in
+		// case it does, I'm raising an error to inspire investigation. -- lanechr
+		return nil, fmt.Errorf("Too many changes returned for query '%d'", changeNumber)
+	}
+	return &clList[0], nil
+}
+
 // Submit submits the given changelist through Gerrit.
 func (g *Gerrit) Submit(changeID string) (e error) {
 	cred, err := hostCredentials(g.s, g.host)