Skip to content

Commit

Permalink
Merge pull request #227 from 0lmi/qa-566_command_to_sync_branch
Browse files Browse the repository at this point in the history
QA-566: feat: sync command to trigger repos sync by a comment
  • Loading branch information
0lmi committed Mar 14, 2023
2 parents 2087390 + 95a1d3c commit c954c4e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const (
commandStartPipeline = "start pipeline"
commandCherryPickBranch = "cherry-pick to:"
commandConventionalCommit = "mark-pr as"
commandSyncRepos = "sync"
)

func getConfig() (*config, error) {
Expand Down Expand Up @@ -185,7 +186,7 @@ func processGitHubWebhookRequest(
conf *config,
) {
webhookType := github.WebHookType(ctx.Request)
webhookEvent, _ := github.ParseWebHook(github.WebHookType(ctx.Request), payload)
webhookEvent, _ := github.ParseWebHook(webhookType, payload)
_ = processGitHubWebhook(ctx, webhookType, webhookEvent, githubClient, conf)
}

Expand Down
23 changes: 23 additions & 0 deletions main_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/gin-gonic/gin"
"github.com/google/go-github/v28/github"
"github.com/sirupsen/logrus"

clientgithub "github.com/mendersoftware/integration-test-runner/client/github"
)
Expand Down Expand Up @@ -136,6 +137,8 @@ func processGitHubComment(
if err != nil {
log.Error(err)
}
case strings.Contains(commentBody, commandSyncRepos):
syncPRBranch(ctx, comment, pr, log, conf)
default:
log.Warnf("no command found: %s", commentBody)
return nil
Expand All @@ -144,6 +147,26 @@ func processGitHubComment(
return nil
}

func syncPRBranch(
ctx *gin.Context,
comment *github.IssueCommentEvent,
pr *github.PullRequest,
log *logrus.Entry,
conf *config,
) {
prEvent := &github.PullRequestEvent{
Repo: comment.GetRepo(),
Number: github.Int(pr.GetNumber()),
PullRequest: pr,
}
if _, err := syncPullRequestBranch(log, prEvent, conf); err != nil {
mainErrMsg := "There was an error syncing branches"
log.Errorf(mainErrMsg+": %s", err.Error())
msg := mainErrMsg + ", " + msgDetailsKubernetesLog
postGitHubMessage(ctx, prEvent, log, msg)
}
}

//parsing `start pipeline --pr mender-connect/pull/88/head --pr deviceconnect/pull/12/head
//--pr mender/3.1.x --fast sugar pretty please`
// BuildOptions {
Expand Down
17 changes: 9 additions & 8 deletions main_pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
var (
changelogPrefix = "Merging these commits will result in the following changelog entries:\n\n"
warningHeader = "\n\n## Warning\n\nGenerating changelogs also resulted in these warnings:\n\n"

msgDetailsKubernetesLog = "see <a href=\"https://console.cloud.google.com/kubernetes/" +
"deployment/us-east1/company-websites/default/test-runner-mender-io/logs?" +
"project=gp-kubernetes-269000\">logs</a> for details."
)

type retryParams struct {
Expand Down Expand Up @@ -73,13 +77,10 @@ func processGitHubPullRequest(
log.Debugf("Processing pull request action %s", action)
switch action {
case "opened", "reopened", "synchronize", "ready_for_review":
msgDetails := "see <a href=\"https://console.cloud.google.com/kubernetes/" +
"deployment/us-east1/company-websites/default/test-runner-mender-io/logs?" +
"project=gp-kubernetes-269000\">logs</a> for details."
// We always create a pr_* branch
if prRef, err = syncPullRequestBranch(log, pr, conf); err != nil {
log.Errorf("Could not create PR branch: %s", err.Error())
msg := "There was an error syncing branches, " + msgDetails
msg := "There was an error syncing branches, " + msgDetailsKubernetesLog
postGitHubMessage(ctx, pr, log, msg)
}
//and we run a pipeline only for the pr_* branch
Expand Down Expand Up @@ -113,7 +114,7 @@ func processGitHubPullRequest(
},
})
if err != nil {
msg := "There was an error running your pipeline, " + msgDetails
msg := "There was an error running your pipeline, " + msgDetailsKubernetesLog
postGitHubMessage(ctx, pr, log, msg)
}
}
Expand Down Expand Up @@ -185,15 +186,15 @@ func processGitHubPullRequest(
<summary>my commands and options</summary>
<br />
You can trigger a pipeline on multiple prs with:
- mentioning me and ` + "`" + `start pipeline --pr mender/127 --pr mender-connect/255` + "`" + `
You can start a fast pipeline, disabling full integration tests with:
- mentioning me and ` + "`" + `start pipeline --fast` + "`" + `
You can cherry pick to a given branch or branches with:
You can trigger GitHub->GitLab branch sync with:
- mentioning me and ` + "`" + `sync` + "`" + `
You can cherry pick to a given branch or branches with:
- mentioning me and:
` + "```" + `
cherry-pick to:
Expand Down

0 comments on commit c954c4e

Please sign in to comment.