-
Notifications
You must be signed in to change notification settings - Fork 17
/
prs.go
52 lines (48 loc) · 1.33 KB
/
prs.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package render
import (
"context"
"fmt"
"strings"
"github.com/akuity/kargo-render/internal/github"
"github.com/akuity/kargo-render/pkg/git"
)
func openPR(ctx context.Context, rc requestContext) (string, error) {
commitMsgParts := strings.SplitN(rc.target.commit.message, "\n", 2)
var title string
if rc.target.branchConfig.PRs.UseUniqueBranchNames {
// PR title is just the first line of the commit message
title = fmt.Sprintf("%s <-- %s", rc.request.TargetBranch, commitMsgParts[0])
} else {
// Something more generic because this PR can be updated with more commits
title =
fmt.Sprintf("%s <-- latest batched changes", rc.request.TargetBranch)
}
// TODO: Support git providers other than GitHub.
//
// Wish list:
//
// * GitHub Enterprise
// * Bitbucket
// * Azure DevOps
// * GitLab
// * Other?
url, err := github.OpenPR(
ctx,
rc.request.RepoURL,
title,
"See individual commit messages for details.",
rc.request.TargetBranch,
rc.target.commit.branch,
git.RepoCredentials{
Username: rc.request.RepoCreds.Username,
Password: rc.request.RepoCreds.Password,
},
)
// TODO: Catch specific errors that have to do with an open PR already being
// associated with the target branch
if err != nil {
return "",
fmt.Errorf("error opening pull request to the target branch: %w", err)
}
return url, nil
}