diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index bf372de2533223..183b130cb23860 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest - container: eu.gcr.io/gitpod-core-dev/dev/changelog:0.0.34 + container: eu.gcr.io/gitpod-core-dev/dev/changelog:0.0.36 steps: - uses: actions/checkout@v2 @@ -24,10 +24,11 @@ jobs: git add CHANGELOG.md git commit -m "[changelog] updated changelog" git push origin $PR_BRANCH - /app/changelog pr -t $TOKEN -o gitpod-io -r gitpod -b $GITHUB_REF -H $PR_BRANCH + /app/changelog pr -t $TOKEN -a $APPROVAL_TOKEN -o gitpod-io -r gitpod -b $GITHUB_REF -H $PR_BRANCH fi env: GITHUB_USER: roboquat GITHUB_EMAIL: roboquat@gitpod.io TOKEN: ${{ secrets.ROBOQUAT_AUTOMATIC_CHANGELOG }} + APPROVAL_TOKEN: ${{ secrets.GITOPS_BOT_PR_APPROVAL_TOKEN }} shell: bash diff --git a/dev/changelog/pullrequest.go b/dev/changelog/pullrequest.go index cfd33325dbf1ed..c7461c9a8f4060 100644 --- a/dev/changelog/pullrequest.go +++ b/dev/changelog/pullrequest.go @@ -16,13 +16,14 @@ import ( ) type PullRequestOptions struct { - Title string - Body string - Token string - Org string - Repo string - BaseBranch string - HeadBranch string + Title string + Body string + Token string + ApprovalToken string + Org string + Repo string + BaseBranch string + HeadBranch string } var prOpts = &PullRequestOptions{} @@ -33,6 +34,9 @@ var pullRequestCommand = &cobra.Command{ Short: "Creates a PR to update the changelog.", Run: func(c *cobra.Command, args []string) { client := NewClient(prOpts.Token) + // PRs can't be approved by the author of the PR. Thus we need two clients. + // One for creating the PR and one for approving it. + approvalClient := NewClient(prOpts.ApprovalToken) context := context.Background() newPr := &github.NewPullRequest{ Title: &prOpts.Title, @@ -100,6 +104,22 @@ var pullRequestCommand = &cobra.Command{ l += *label.Name } logger.WithField("labels", l).WithField("pr", pr.Number).Info("PR labels successfully added") + + retries = 0 + for { + retries++ + if retries > 60 { + logger.WithError(err).Fatal("Timeout trying to approve PR") + } + event := "APPROVE" + _, _, err := approvalClient.PullRequests.CreateReview(context, prOpts.Org, prOpts.Repo, *pr.Number, &github.PullRequestReviewRequest{Event: &event}) + if err != nil { + logger.WithError(err).Error("Error approving PR. Trying again in a bit.") + time.Sleep(time.Second) + } else { + break + } + } }, } @@ -107,6 +127,7 @@ func init() { // Setup prFlags before the command is initialized prFlags := pullRequestCommand.PersistentFlags() prFlags.StringVarP(&prOpts.Token, "token", "t", prOpts.Token, "a GitHub personal API token to perform authenticated requests") + prFlags.StringVarP(&prOpts.ApprovalToken, "approval-token", "a", prOpts.Token, "a GitHub personal API token to perform PR approval") prFlags.StringVarP(&prOpts.Org, "org", "o", prOpts.Org, "the github organization") prFlags.StringVarP(&prOpts.Repo, "repo", "r", prOpts.Repo, "the github repository name") prFlags.StringVarP(&prOpts.HeadBranch, "head", "H", "main", "the head branch for pull requests")