Skip to content

Commit e3d2f8e

Browse files
jajitanotrepo05
authored andcommitted
rename variables for code readability
use "github_host" env var to fetch release notes for bosh releases bump Co-authored-by: Nick Rohn <[email protected]>
1 parent 5371842 commit e3d2f8e

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ stemcell_criteria:
658658
- type: github
659659
id: optional-unique-name-defaults-to-github-org-name
660660
org: the-github-org
661+
endpoint: $(variable "github_host")
661662
github_token: $(variable "github_token")
662663
```
663664

internal/commands/release_notes.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const releaseDateFormat = "2006-01-02"
2828

2929
type ReleaseNotes struct {
3030
Options struct {
31-
ReleaseDate string `long:"release-date" short:"d" description:"release date of the tile"`
32-
TemplateName string `long:"template" short:"t" description:"path to template"`
33-
GithubToken string `long:"github-token" short:"g" description:"auth token for fetching issues merged between releases" env:"GITHUB_TOKEN"`
34-
GithubHost string `long:"github-host" description:"set this when you are using GitHub enterprise" env:"GITHUB_HOST"`
35-
Kilnfile string `long:"kilnfile" short:"k" description:"path to Kilnfile"`
36-
DocsFile string `long:"update-docs" short:"u" description:"path to docs file to update"`
37-
Window string `long:"window" short:"w" description:"GA window for release notes" default:"ga"`
38-
VariableFiles []string `long:"variables-file" short:"vf" description:"path to a file containing variables to interpolate"`
39-
Variables []string `long:"variable" short:"vr" description:"key value pairs of variables to interpolate"`
31+
ReleaseDate string `long:"release-date" short:"d" description:"release date of the tile"`
32+
TemplateName string `long:"template" short:"t" description:"path to template"`
33+
GithubIssuesServiceToken string `long:"github-token" short:"g" description:"auth token for fetching issues and milestones with labels" env:"GITHUB_TOKEN"`
34+
GithubHost string `long:"github-host" description:"set this when you are using GitHub enterprise to fetch issues, milestones or notes for bosh releases" env:"GITHUB_HOST"`
35+
Kilnfile string `long:"kilnfile" short:"k" description:"path to Kilnfile"`
36+
DocsFile string `long:"update-docs" short:"u" description:"path to docs file to update"`
37+
Window string `long:"window" short:"w" description:"GA window for release notes" default:"ga"`
38+
VariableFiles []string `long:"variables-file" short:"vf" description:"path to a file containing variables to interpolate"`
39+
Variables []string `long:"variable" short:"vr" description:"key value pairs of variables to interpolate"`
4040
notes.IssuesQuery
4141
notes.TrainstatQuery
4242
}
@@ -82,10 +82,16 @@ func (r ReleaseNotes) Execute(args []string) error {
8282
if err != nil {
8383
return fmt.Errorf("failed to parse template variables: %s", err)
8484
}
85-
if varValue, ok := templateVariables["github_token"]; !ok && r.Options.GithubToken != "" {
86-
templateVariables["github_token"] = r.Options.GithubToken
87-
} else if ok && r.Options.GithubToken == "" {
88-
r.Options.GithubToken = varValue.(string)
85+
if varValue, ok := templateVariables["github_token"]; !ok && r.Options.GithubIssuesServiceToken != "" {
86+
templateVariables["github_token"] = r.Options.GithubIssuesServiceToken
87+
} else if ok && r.Options.GithubIssuesServiceToken == "" {
88+
r.Options.GithubIssuesServiceToken = varValue.(string)
89+
}
90+
91+
if varValue, ok := templateVariables["github_host"]; !ok && r.Options.GithubHost != "" {
92+
templateVariables["github_host"] = r.Options.GithubHost
93+
} else if ok && r.Options.GithubHost == "" {
94+
r.Options.GithubHost = varValue.(string)
8995
}
9096

9197
ctx := context.Background()
@@ -100,8 +106,8 @@ func (r ReleaseNotes) Execute(args []string) error {
100106
}
101107

102108
var client *github.Client
103-
if r.Options.GithubToken != "" {
104-
client, err = gh.Client(ctx, r.Options.GithubHost, r.Options.GithubToken)
109+
if r.Options.GithubIssuesServiceToken != "" {
110+
client, err = gh.Client(ctx, r.Options.GithubHost, r.Options.GithubIssuesServiceToken)
105111
if err != nil {
106112
return fmt.Errorf("failed to setup github client: %w", err)
107113
}
@@ -237,7 +243,7 @@ func (r ReleaseNotes) checkInputs(nonFlagArgs []string) error {
237243
}
238244
}
239245

240-
if r.Options.GithubToken == "" &&
246+
if r.Options.GithubIssuesServiceToken == "" &&
241247
(r.Options.IssueMilestone != "" ||
242248
len(r.Options.IssueIDs) > 0 ||
243249
len(r.Options.IssueLabels) > 0) {

internal/commands/release_notes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestReleaseNotes_Execute(t *testing.T) {
104104
},
105105
}
106106

107-
rn.Options.GithubToken = "secret"
107+
rn.Options.GithubIssuesServiceToken = "secret"
108108

109109
err := rn.Execute([]string{
110110
"--kilnfile=tile/Kilnfile",

pkg/cargo/bump.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ type repositoryReleaseLister interface {
129129

130130
type (
131131
RepositoryReleaseLister = repositoryReleaseLister
132-
githubClientFunc func(ctx context.Context, kilnfile Kilnfile, lock BOSHReleaseTarballLock) (repositoryReleaseLister, error)
132+
githubReleasesClient func(ctx context.Context, kilnfile Kilnfile, lock BOSHReleaseTarballLock) (repositoryReleaseLister, error)
133133
)
134134

135-
func releaseNotes(ctx context.Context, kf Kilnfile, list BumpList, client githubClientFunc) (BumpList, error) {
135+
// Fetch release notes for each of the release bumps in the Kilnfile
136+
func releaseNotes(ctx context.Context, kf Kilnfile, list BumpList, getGithubRepositoryClientForRelease githubReleasesClient) (BumpList, error) {
136137
const workerCount = 10
137138

138139
type fetchReleaseNotesForBump struct {
@@ -152,7 +153,7 @@ func releaseNotes(ctx context.Context, kf Kilnfile, list BumpList, client github
152153
go func() {
153154
defer wg.Done()
154155
for j := range in {
155-
j.bump = fetchReleasesForBump(ctx, kf, j.bump, client)
156+
j.bump = fetchReleasesForBump(ctx, kf, j.bump, getGithubRepositoryClientForRelease)
156157
results <- j
157158
}
158159
}()
@@ -184,10 +185,10 @@ func releaseNotes(ctx context.Context, kf Kilnfile, list BumpList, client github
184185
}
185186

186187
func ReleaseNotes(ctx context.Context, kf Kilnfile, list BumpList) (BumpList, error) {
187-
return releaseNotes(ctx, kf, list, listerForRelease(kf))
188+
return releaseNotes(ctx, kf, list, getGithubRepositoryClientForRelease(kf))
188189
}
189190

190-
func listerForRelease(kf Kilnfile) func(ctx context.Context, _ Kilnfile, lock BOSHReleaseTarballLock) (repositoryReleaseLister, error) {
191+
func getGithubRepositoryClientForRelease(kf Kilnfile) func(ctx context.Context, _ Kilnfile, lock BOSHReleaseTarballLock) (repositoryReleaseLister, error) {
191192
return func(ctx context.Context, kilnfile Kilnfile, lock BOSHReleaseTarballLock) (repositoryReleaseLister, error) {
192193
spec, err := kf.BOSHReleaseTarballSpecification(lock.Name)
193194
if err != nil {
@@ -214,7 +215,8 @@ func listerForRelease(kf Kilnfile) func(ctx context.Context, _ Kilnfile, lock BO
214215
}
215216
}
216217

217-
func fetchReleasesFromRepo(ctx context.Context, repoService RepositoryReleaseLister, repository string, from, to *semver.Version) []*github.RepositoryRelease {
218+
// Fetch all the releases from GitHub repository between from and to versions
219+
func fetchReleasesFromRepo(ctx context.Context, releaseLister RepositoryReleaseLister, repository string, from, to *semver.Version) []*github.RepositoryRelease {
218220
owner, repo, err := gh.RepositoryOwnerAndNameFromPath(repository)
219221
if err != nil {
220222
return nil
@@ -223,7 +225,7 @@ func fetchReleasesFromRepo(ctx context.Context, repoService RepositoryReleaseLis
223225
var result []*github.RepositoryRelease
224226

225227
ops := github.ListOptions{}
226-
releases, _, err := repoService.ListReleases(ctx, owner, repo, &ops)
228+
releases, _, err := releaseLister.ListReleases(ctx, owner, repo, &ops)
227229
if err != nil {
228230
log.Println(err)
229231
}
@@ -239,7 +241,7 @@ func fetchReleasesFromRepo(ctx context.Context, repoService RepositoryReleaseLis
239241
return result
240242
}
241243

242-
func fetchReleasesForBump(ctx context.Context, kf Kilnfile, bump Bump, client githubClientFunc) Bump {
244+
func fetchReleasesForBump(ctx context.Context, kf Kilnfile, bump Bump, getGithubRepositoryClientForRelease githubReleasesClient) Bump {
243245
spec, err := kf.BOSHReleaseTarballSpecification(bump.Name)
244246
if err != nil {
245247
return bump
@@ -250,7 +252,8 @@ func fetchReleasesForBump(ctx context.Context, kf Kilnfile, bump Bump, client gi
250252
return bump
251253
}
252254

253-
lister, err := client(ctx, kf, bump.To)
255+
// Fetch the GitHub releases client for a single release (bump) in the Kilnfile
256+
releaseLister, err := getGithubRepositoryClientForRelease(ctx, kf, bump.To)
254257
if err != nil {
255258
log.Println(err)
256259
return bump
@@ -262,7 +265,7 @@ func fetchReleasesForBump(ctx context.Context, kf Kilnfile, bump Bump, client gi
262265
}
263266

264267
if spec.GitHubRepository != "" {
265-
releases := fetchReleasesFromRepo(ctx, lister, spec.GitHubRepository, from, to)
268+
releases := fetchReleasesFromRepo(ctx, releaseLister, spec.GitHubRepository, from, to)
266269
bump.Releases = append(bump.Releases, releases...)
267270
}
268271

pkg/notes/notes_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ type issuesService interface {
357357
// manual test to ensure it continues to behave as expected during refactors.
358358
//
359359
// The function can be tested by generating release notes for a tile with issue ids and a milestone set. The happy path
360-
// test for Execute does not set GithubToken intentionally so this code is not triggered and Execute does not actually
360+
// test for Execute does not set GithubIssuesServiceToken intentionally so this code is not triggered and Execute does not actually
361361
// reach out to GitHub.
362362
func (r fetchNotesData) fetchIssuesAndReleaseNotes(ctx context.Context, finalKF, wtKF cargo.Kilnfile, bumpList cargo.BumpList, issuesQuery IssuesQuery) ([]*github.Issue, cargo.BumpList, error) {
363363
if r.issuesService == nil {

0 commit comments

Comments
 (0)