-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote.go
37 lines (29 loc) · 832 Bytes
/
vote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package vsts
import (
"log"
"strconv"
"strings"
)
func getReviewerURL(pullRequestID int) string {
reviewerURLTemplate := "https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}/pullRequests/{pullRequest}/reviewers/{reviewer}?api-version={version}"
r := strings.NewReplacer(
"{instance}", config.Instance,
"{project}", config.Project,
"{repository}", config.Repo,
"{pullRequest}", strconv.Itoa(pullRequestID),
"{reviewer}", config.UserID,
"{version}", "3.0-preview")
return r.Replace(reviewerURLTemplate)
}
func votePullRequest(pullRequestID int, vote int) error {
log.Printf("Vote on PR %v: %v...\n", pullRequestID, vote)
putVote := putVote{
Vote: vote,
}
url := getReviewerURL(pullRequestID)
err := putToVsts(url, putVote)
if err != nil {
return err
}
return nil
}