Skip to content

Commit

Permalink
Merge pull request #110 from AdeAttwood/master
Browse files Browse the repository at this point in the history
Updates to Gitlab PRs
  • Loading branch information
nathanleiby authored Aug 16, 2021
2 parents 52adc7f + f4d640e commit 568adcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
27 changes: 17 additions & 10 deletions push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,7 @@ func GithubPush(ctx context.Context, input Input, repoLimiter *time.Ticker, push
}
base := *repository.DefaultBranch

// Determine PR title and body
// Title is first line of commit message.
// Body is the remainder of the commit message after title AND/OR `body-file` content if given
title := input.CommitMessage
body := input.PRBody
splitMsg := strings.SplitN(input.CommitMessage, "\n", 2)
if len(splitMsg) == 2 {
title = splitMsg[0]
body = splitMsg[1] + "\n" + input.PRBody
}
title, body := getTitleBody(input)
pr, err := findOrCreatePR(ctx, client, input.Repo.Owner, input.Repo.Name, &github.NewPullRequest{
Title: &title,
Body: &body,
Expand Down Expand Up @@ -220,3 +211,19 @@ func findOrCreatePR(ctx context.Context, client *github.Client, owner string, na
func different(s1, s2 *string) bool {
return s1 != nil && s2 != nil && *s1 != *s2
}

// Determine PR title and body
// Title is first line of commit message.
// Body is the remainder of the commit message after title AND/OR `body-file` content if given
func getTitleBody(input Input) (string, string) {
title := input.CommitMessage
body := input.PRBody

splitMsg := strings.SplitN(input.CommitMessage, "\n", 2)
if len(splitMsg) == 2 {
title = splitMsg[0]
body = splitMsg[1] + "\n" + input.PRBody
}

return title, body
}
21 changes: 7 additions & 14 deletions push/pushGitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,16 @@ func GitlabPush(ctx context.Context, input Input, repoLimiter *time.Ticker, push
return Output{Success: false}, errors.New(string(output))
}

project, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", input.Repo.Owner, input.Repo.Name), nil)
if err != nil {
return Output{Success: false}, err
}

// Open a pull request, if one doesn't exist already
head := input.BranchName
base := "master"

// Determine MR title and body
// Title is first line of commit message.
// Body is given by body-file if it exists or is the remainder of the commit message after title.
title := input.CommitMessage
body := ""
splitMsg := strings.SplitN(input.CommitMessage, "\n", 2)
if len(splitMsg) == 2 {
title = splitMsg[0]
if input.PRBody == "" {
body = splitMsg[1]
}
}
base := project.DefaultBranch

title, body := getTitleBody(input)
pr, err := findOrCreateGitlabMR(ctx, client, input.Repo.Owner, input.Repo.Name, &gitlab.CreateMergeRequestOptions{
Title: &title,
Description: &body,
Expand Down

0 comments on commit 568adcd

Please sign in to comment.