-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.go
35 lines (27 loc) · 951 Bytes
/
diff.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
package vsts
import (
"strings"
)
func getBranchNameFromRefName(refName string) string {
return (strings.SplitAfterN(refName, "/", 3))[2]
}
func getdiffsURL(baseBranch string, targetBranch string) string {
diffsURLTemplate := "https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}/diffs/commits?api-version={version}&targetVersionType=branch&targetVersion={targetBranch}&baseVersionType=branch&baseVersion={baseBranch}"
r := strings.NewReplacer(
"{instance}", config.Instance,
"{project}", config.Project,
"{repository}", config.Repo,
"{version}", "1.0",
"{baseBranch}", baseBranch,
"{targetBranch}", targetBranch)
return r.Replace(diffsURLTemplate)
}
func getDiffsBetweenBranches(baseBranch string, targetBranch string) (*diffs, error) {
diffs := new(diffs)
url := getdiffsURL(baseBranch, targetBranch)
err := getFromVsts(url, diffs)
if err != nil {
return nil, err
}
return diffs, nil
}