Skip to content

Commit

Permalink
[changelog] improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKoehnlein authored and roboquat committed Sep 8, 2021
1 parent 8b966d0 commit 705a531
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 6 additions & 5 deletions .werft/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pod:
cloud.google.com/gke-nodepool: builds
containers:
- name: build
image: eu.gcr.io/gitpod-core-dev/dev/changelog:0.0.13
image: eu.gcr.io/gitpod-core-dev/dev/changelog:0.0.18
workingDir: /workspace
imagePullPolicy: Always
env:
Expand All @@ -24,17 +24,18 @@ pod:
- |
sleep 1
set -Eeuo pipefail
export GITHUB_TOKEN=$(echo $GITHUB_TOKEN | xargs)
export GIT_REF={{ .Repository.Ref }}
export GIT_BRANCH=${GIT_REF/refs\/heads\//}
git checkout $GIT_BRANCH
/app/changelog -t $GITHUB_TOKEN -o {{ .Repository.Owner }} -r {{ .Repository.Repo }} -b $GIT_BRANCH
export PR_BRANCH=$(date '+rg/changelog_%Y%m%d%H%M')
git checkout -b $PR_BRANCH
/app/changelog update -t $GITHUB_TOKEN -o {{ .Repository.Owner }} -r {{ .Repository.Repo }} -b $GIT_BRANCH
if [[ $(git status --porcelain) ]]; then
git config --global user.name $GITHUB_USER
git config --global user.email $GITHUB_EMAIL
git config --global credential.helper '/bin/sh -c "echo username=$GITHUB_USER; echo password=$GITHUB_TOKEN"'
git add CHANGELOG.md
git commit -m "[changelog] updated changelog"
git push origin $GIT_BRANCH
git push origin $PR_BRANCH
/app/changelog pr -t $GITHUB_TOKEN -o {{ .Repository.Owner }} -r {{ .Repository.Repo }} -b $GIT_BRANCH -H $PR_BRANCH
fi
21 changes: 19 additions & 2 deletions dev/changelog/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"

"github.com/google/go-github/v38/github"
logger "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -31,13 +32,29 @@ var pullRequestCommand = &cobra.Command{
Run: func(c *cobra.Command, args []string) {
client := NewClient(prOpts.Token)
context := context.Background()
pr := &github.NewPullRequest{
newPr := &github.NewPullRequest{
Title: &prOpts.Title,
Body: &prOpts.Body,
Base: &prOpts.BaseBranch,
Head: &prOpts.HeadBranch,
}
client.PullRequests.Create(context, prOpts.Org, prOpts.Repo, pr)
pr, _, err := client.PullRequests.Create(context, prOpts.Org, prOpts.Repo, newPr)
if err != nil {
logger.WithError(err).Fatal("Error creating pull request")
}
logger.WithField("url", pr.URL).WithField("pr", pr.Number).Info("PR successfully created")
labels, _, err := client.Issues.AddLabelsToIssue(context, prOpts.Org, prOpts.Repo, *pr.Number, []string{"lgtm", "approved"})
if err != nil {
logger.WithError(err).Fatal("Error setting labels")
}
l := ""
for _, label := range labels {
if l != "" {
l += ", "
}
l += *label.Name
}
logger.WithField("labels", l).WithField("pr", pr.Number).Info("PR labels successfully added")
},
}

Expand Down
8 changes: 5 additions & 3 deletions dev/changelog/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ var updateCommand = &cobra.Command{
if err != nil {
logger.WithError(err).Fatal("error retrieving PRs")
}
if len(notes) > 0 {
logger.Infof("Adding %d release note entries", len(notes))
WriteFile(opts.ChangelogFile, notes, existingNotes, lastPrDate)
if len(notes) == 0 {
logger.Infof("No new PRs, changelog is up-to-date")
return
}
logger.Infof("Adding %d release note entries", len(notes))
WriteFile(opts.ChangelogFile, notes, existingNotes, lastPrDate)
},
}

Expand Down

0 comments on commit 705a531

Please sign in to comment.