Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 9776c5a

Browse files
committed
add hack script to list all pull requests for each release
1 parent 4db9345 commit 9776c5a

File tree

4,574 files changed

+1256362
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,574 files changed

+1256362
-0
lines changed

Gopkg.lock

Lines changed: 279 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/release.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2018 Google, Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
16+
17+
# you can pass your github token with --token here if you run out of requests
18+
go run ${DIR}/release_notes/listpullreqs.go
19+
20+
echo "Huge thank you for this release towards our contributors: "
21+
git log "$(git describe --abbrev=0)".. --format="%aN" --reverse | sort | uniq | awk '{printf "- %s\n", $0 }'

hack/release_notes/listpullreqs.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright 2018 Google, Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"github.com/google/go-github/github"
24+
"github.com/sirupsen/logrus"
25+
"github.com/spf13/cobra"
26+
"golang.org/x/oauth2"
27+
)
28+
29+
var (
30+
token string
31+
fromTag string
32+
toTag string
33+
)
34+
35+
var rootCmd = &cobra.Command{
36+
Use: "listpullreqs fromTag toTag",
37+
Short: "Lists pull requests between two versions in our changelog markdown format",
38+
ArgAliases: []string{"fromTag", "toTag"},
39+
Run: func(cmd *cobra.Command, args []string) {
40+
printPullRequests()
41+
},
42+
}
43+
44+
const org = "GoogleContainerTools"
45+
const repo = "container-diff"
46+
47+
func main() {
48+
rootCmd.Flags().StringVar(&token, "token", "", "Specify personal Github Token if you are hitting a rate limit anonymously. https://github.com/settings/tokens")
49+
rootCmd.Flags().StringVar(&fromTag, "fromTag", "", "comparison of commits is based on this tag (defaults to the latest tag in the repo)")
50+
rootCmd.Flags().StringVar(&toTag, "toTag", "master", "this is the commit that is compared with fromTag")
51+
if err := rootCmd.Execute(); err != nil {
52+
logrus.Fatal(err)
53+
}
54+
}
55+
56+
func printPullRequests() {
57+
client := getClient()
58+
59+
releases, _, _ := client.Repositories.ListReleases(context.Background(), org, repo, &github.ListOptions{})
60+
lastReleaseTime := *releases[0].PublishedAt
61+
fmt.Println(fmt.Sprintf("Collecting pull request that were merged since the last release: %s (%s)", *releases[0].TagName, lastReleaseTime))
62+
63+
listSize := 1
64+
for page := 0; listSize > 0; page++ {
65+
pullRequests, _, _ := client.PullRequests.List(context.Background(), org, repo, &github.PullRequestListOptions{
66+
State: "closed",
67+
Sort: "updated",
68+
Direction: "desc",
69+
ListOptions: github.ListOptions{
70+
PerPage: 100,
71+
Page: page,
72+
},
73+
})
74+
75+
for idx := range pullRequests {
76+
pr := pullRequests[idx]
77+
if pr.MergedAt != nil {
78+
if pr.GetMergedAt().After(lastReleaseTime.Time) {
79+
fmt.Printf("* %s [#%d](https://github.com/%s/%s/pull/%d)\n", pr.GetTitle(), *pr.Number, org, repo, *pr.Number)
80+
}
81+
}
82+
}
83+
84+
listSize = len(pullRequests)
85+
}
86+
}
87+
88+
func getClient() *github.Client {
89+
if len(token) <= 0 {
90+
return github.NewClient(nil)
91+
}
92+
ctx := context.Background()
93+
ts := oauth2.StaticTokenSource(
94+
&oauth2.Token{AccessToken: token},
95+
)
96+
tc := oauth2.NewClient(ctx, ts)
97+
return github.NewClient(tc)
98+
}

0 commit comments

Comments
 (0)