Skip to content

Commit e0e6271

Browse files
committed
Allow creating/updating the release discussion category
- bump GitHub dep to v35.3.0 as this was introduced in v35.1.0 - add new string flag "discussion-category" (+ env vars) - update release: only set category, if not set - NOTE: Currently it looks like release drafts with discussion category set do not "persist" the category when being released, so when publishing a release draft, without explicitly setting the category, it won't have a release discussion. Nothing we can do here I suppose. Signed-off-by: Thorsten Klein <[email protected]>
1 parent a77f417 commit e0e6271

File tree

5 files changed

+68
-41
lines changed

5 files changed

+68
-41
lines changed

cmd/drone-github-release/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
6363
EnvVars: []string{"PLUGIN_PRERELEASE", "GITHUB_RELEASE_PRERELEASE"},
6464
Destination: &settings.Prerelease,
6565
},
66+
&cli.StringFlag{
67+
Name: "discussion-category",
68+
Usage: "create a discussion in the given category",
69+
EnvVars: []string{"PLUGIN_DISCUSSION_CATEGORY", "GITHUB_RELEASE_DISCUSSION_CATEGORY"},
70+
Destination: &settings.DiscussionCategory,
71+
},
6672
&cli.StringFlag{
6773
Name: "base-url",
6874
Usage: "api url, needs to be changed for ghe",

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.15
44

55
require (
66
github.com/drone-plugins/drone-plugin-lib v0.4.0
7-
github.com/google/go-github/v35 v35.0.0
7+
github.com/google/go-github/v35 v35.3.0
88
github.com/joho/godotenv v1.3.0
99
github.com/urfave/cli/v2 v2.3.0
10-
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78
10+
golang.org/x/oauth2 v0.0.0-20210622215436-a8dc77f794b6
1111
)

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
8686
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
8787
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
8888
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
89+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
8990
github.com/google/go-github/v35 v35.0.0 h1:oLrHdYkSQvbhN4gJihpEkTFKAZnIFgTCj1p/OlE4Os4=
9091
github.com/google/go-github/v35 v35.0.0/go.mod h1:s0515YVTI+IMrDoy9Y4pHt9ShGpzHvHO8rZ7L7acgvs=
92+
github.com/google/go-github/v35 v35.3.0 h1:fU+WBzuukn0VssbayTT+Zo3/ESKX9JYWjbZTLOTEyho=
93+
github.com/google/go-github/v35 v35.3.0/go.mod h1:yWB7uCcVWaUbUP74Aq3whuMySRMatyRmq5U9FTNlbio=
9194
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
9295
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
9396
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
@@ -210,6 +213,8 @@ golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4Iltr
210213
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
211214
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 h1:rPRtHfUb0UKZeZ6GH4K4Nt4YRbE9V1u+QZX5upZXqJQ=
212215
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
216+
golang.org/x/oauth2 v0.0.0-20210622215436-a8dc77f794b6 h1:pERGha6IgvMUdN6oJbwjZTt1ai5/O855Qmv1Bsc0v18=
217+
golang.org/x/oauth2 v0.0.0-20210622215436-a8dc77f794b6/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
213218
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
214219
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
215220
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

plugin/impl.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ import (
1919

2020
// Settings for the plugin.
2121
type Settings struct {
22-
APIKey string
23-
Files cli.StringSlice
24-
FileExists string
25-
Checksum cli.StringSlice
26-
ChecksumFile string
27-
ChecksumFlatten bool
28-
Draft bool
29-
Prerelease bool
30-
BaseURL string
31-
UploadURL string
32-
Title string
33-
Note string
34-
Overwrite bool
22+
APIKey string
23+
Files cli.StringSlice
24+
FileExists string
25+
Checksum cli.StringSlice
26+
ChecksumFile string
27+
ChecksumFlatten bool
28+
Draft bool
29+
Prerelease bool
30+
DiscussionCategory string
31+
BaseURL string
32+
UploadURL string
33+
Title string
34+
Note string
35+
Overwrite bool
3536

3637
baseURL *url.URL
3738
uploadURL *url.URL
@@ -125,17 +126,18 @@ func (p *Plugin) Execute() error {
125126
client.UploadURL = p.settings.uploadURL
126127

127128
rc := releaseClient{
128-
Client: client,
129-
Context: p.network.Context,
130-
Owner: p.pipeline.Repo.Owner,
131-
Repo: p.pipeline.Repo.Name,
132-
Tag: strings.TrimPrefix(p.pipeline.Commit.Ref, "refs/tags/"),
133-
Draft: p.settings.Draft,
134-
Prerelease: p.settings.Prerelease,
135-
FileExists: p.settings.FileExists,
136-
Title: p.settings.Title,
137-
Note: p.settings.Note,
138-
Overwrite: p.settings.Overwrite,
129+
Client: client,
130+
Context: p.network.Context,
131+
Owner: p.pipeline.Repo.Owner,
132+
Repo: p.pipeline.Repo.Name,
133+
Tag: strings.TrimPrefix(p.pipeline.Commit.Ref, "refs/tags/"),
134+
Draft: p.settings.Draft,
135+
Prerelease: p.settings.Prerelease,
136+
DiscussionCategory: p.settings.DiscussionCategory,
137+
FileExists: p.settings.FileExists,
138+
Title: p.settings.Title,
139+
Note: p.settings.Note,
140+
Overwrite: p.settings.Overwrite,
139141
}
140142

141143
release, err := rc.buildRelease()

plugin/release.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ import (
1818
type releaseClient struct {
1919
*github.Client
2020
context.Context
21-
Owner string
22-
Repo string
23-
Tag string
24-
Draft bool
25-
Prerelease bool
26-
FileExists string
27-
Title string
28-
Note string
29-
Overwrite bool
21+
Owner string
22+
Repo string
23+
Tag string
24+
Draft bool
25+
Prerelease bool
26+
DiscussionCategory string
27+
FileExists string
28+
Title string
29+
Note string
30+
Overwrite bool
3031
}
3132

3233
func (rc *releaseClient) buildRelease() (*github.RepositoryRelease, error) {
@@ -95,13 +96,19 @@ func (rc *releaseClient) editRelease(targetRelease github.RepositoryRelease) (*g
9596
// only potentially change the draft value, if it's a draft right now
9697
// i.e. a drafted release will be published, but a release won't be unpublished
9798
if targetRelease.GetDraft() {
98-
fmt.Printf("DRAFT: %+v\n", rc.Draft)
9999
if !rc.Draft {
100100
fmt.Println("Publishing a release draft")
101101
}
102102
sourceRelease.Draft = &rc.Draft
103103
}
104104

105+
// do not overwrite the discussion category
106+
if targetRelease.GetDiscussionCategoryName() == "" {
107+
if rc.DiscussionCategory != "" {
108+
sourceRelease.DiscussionCategoryName = &rc.DiscussionCategory
109+
}
110+
}
111+
105112
modifiedRelease, _, err := rc.Client.Repositories.EditRelease(rc.Context, rc.Owner, rc.Repo, targetRelease.GetID(), sourceRelease)
106113

107114
if err != nil {
@@ -114,11 +121,12 @@ func (rc *releaseClient) editRelease(targetRelease github.RepositoryRelease) (*g
114121

115122
func (rc *releaseClient) newRelease() (*github.RepositoryRelease, error) {
116123
rr := &github.RepositoryRelease{
117-
TagName: github.String(rc.Tag),
118-
Draft: &rc.Draft,
119-
Prerelease: &rc.Prerelease,
120-
Name: &rc.Title,
121-
Body: &rc.Note,
124+
TagName: github.String(rc.Tag),
125+
Draft: &rc.Draft,
126+
Prerelease: &rc.Prerelease,
127+
DiscussionCategoryName: &rc.DiscussionCategory,
128+
Name: &rc.Title,
129+
Body: &rc.Note,
122130
}
123131

124132
if *rr.Prerelease {
@@ -133,6 +141,12 @@ func (rc *releaseClient) newRelease() (*github.RepositoryRelease, error) {
133141
fmt.Printf("Release %s will be created and published\n", rc.Tag)
134142
}
135143

144+
if *rr.DiscussionCategoryName != "" {
145+
fmt.Printf("Release discussion in category %s\n", *rr.DiscussionCategoryName)
146+
} else {
147+
fmt.Println("Not creating a discussion")
148+
}
149+
136150
release, _, err := rc.Client.Repositories.CreateRelease(rc.Context, rc.Owner, rc.Repo, rr)
137151

138152
if err != nil {

0 commit comments

Comments
 (0)