Skip to content

Commit 99d79e9

Browse files
authored
Merge pull request #524 from midnightconman/midnight/gh-constant-20251006
Use github DefaultHost Constant Where Possible
2 parents 87810a7 + 0cbb15d commit 99d79e9

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

pkg/plugins/assign/assign.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type handler struct {
190190
func newAssignHandler(e github.GenericCommentEvent, gc githubClient, log *logrus.Entry) *handler {
191191
org := e.Repo.Owner.Login
192192
addFailureResponse := func(mu github.MissingUsers) string {
193-
return fmt.Sprintf("GitHub didn't allow me to assign the following users: %s.\n\nNote that only [%s members](https://github.com/orgs/%s/people) with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.\nFor more information please see [the contributor guide](https://git.k8s.io/community/contributors/guide/first-contribution.md#issue-assignment-in-github)", strings.Join(mu.Users, ", "), org, org)
193+
return fmt.Sprintf("GitHub didn't allow me to assign the following users: %s.\n\nNote that only [%s members](https://%s/orgs/%s/people) with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.\nFor more information please see [the contributor guide](https://git.k8s.io/community/contributors/guide/first-contribution.md#issue-assignment-in-github)", strings.Join(mu.Users, ", "), org, github.DefaultHost, org)
194194
}
195195

196196
return &handler{
@@ -208,7 +208,7 @@ func newAssignHandler(e github.GenericCommentEvent, gc githubClient, log *logrus
208208
func newReviewHandler(e github.GenericCommentEvent, gc githubClient, log *logrus.Entry) *handler {
209209
org := e.Repo.Owner.Login
210210
addFailureResponse := func(mu github.MissingUsers) string {
211-
return fmt.Sprintf("GitHub didn't allow me to request PR reviews from the following users: %s.\n\nNote that only [%s members](https://github.com/orgs/%s/people) and repo collaborators can review this PR, and authors cannot review their own PRs.", strings.Join(mu.Users, ", "), org, org)
211+
return fmt.Sprintf("GitHub didn't allow me to request PR reviews from the following users: %s.\n\nNote that only [%s members](https://%s/orgs/%s/people) and repo collaborators can review this PR, and authors cannot review their own PRs.", strings.Join(mu.Users, ", "), org, github.DefaultHost, org)
212212
}
213213

214214
return &handler{

pkg/plugins/bugzilla/bugzilla.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ func handleMerge(e event, gc githubClient, bc bugzilla.Client, options plugins.B
996996
pr, err := gc.GetPullRequest(item.Org, item.Repo, item.Num)
997997
if err != nil {
998998
log.WithError(err).Warn("Unexpected error checking merge state of related pull request.")
999-
return comment(formatError(fmt.Sprintf("checking the state of a related pull request at https://github.com/%s/%s/pull/%d", item.Org, item.Repo, item.Num), bc.Endpoint(), e.bugId, err))
999+
return comment(formatError(fmt.Sprintf("checking the state of a related pull request at https://%s/%s/%s/pull/%d", github.DefaultHost, item.Org, item.Repo, item.Num), bc.Endpoint(), e.bugId, err))
10001000
}
10011001
merged = pr.Merged
10021002
state = pr.State
@@ -1017,7 +1017,7 @@ func handleMerge(e event, gc githubClient, bc bugzilla.Client, options plugins.B
10171017
}
10181018

10191019
link := func(bug bugzilla.ExternalBug) string {
1020-
return fmt.Sprintf("[%s/%s#%d](https://github.com/%s/%s/pull/%d)", bug.Org, bug.Repo, bug.Num, bug.Org, bug.Repo, bug.Num)
1020+
return fmt.Sprintf("[%s/%s#%d](https://%s/%s/%s/pull/%d)", bug.Org, bug.Repo, bug.Num, github.DefaultHost, bug.Org, bug.Repo, bug.Num)
10211021
}
10221022

10231023
mergedMessage := func(statement string) string {
@@ -1068,7 +1068,7 @@ func handleCherrypick(e event, gc githubClient, bc bugzilla.Client, options plug
10681068
pr, err := gc.GetPullRequest(e.org, e.repo, e.cherrypickFromPRNum)
10691069
if err != nil {
10701070
log.WithError(err).Warn("Unexpected error getting title of pull request being cherrypicked from.")
1071-
return comment(fmt.Sprintf("Error creating a cherry-pick bug in Bugzilla: failed to check the state of cherrypicked pull request at https://github.com/%s/%s/pull/%d: %v.\nPlease contact an administrator to resolve this issue, then request a bug refresh with <code>/bugzilla refresh</code>.", e.org, e.repo, e.cherrypickFromPRNum, err))
1071+
return comment(fmt.Sprintf("Error creating a cherry-pick bug in Bugzilla: failed to check the state of cherrypicked pull request at https://%s/%s/%s/pull/%d: %v.\nPlease contact an administrator to resolve this issue, then request a bug refresh with <code>/bugzilla refresh</code>.", github.DefaultHost, e.org, e.repo, e.cherrypickFromPRNum, err))
10721072
}
10731073
// Attempt to identify bug from PR title
10741074
bugID, bugMissing, err := bugIDFromTitle(pr.Title)
@@ -1239,7 +1239,7 @@ func handleClose(e event, gc githubClient, bc bugzilla.Client, options plugins.B
12391239
}
12401240
response += fmt.Sprintf(" All external bug links have been closed. The bug has been moved to the %s state.", options.StateAfterClose)
12411241
}
1242-
bzComment := &bugzilla.CommentCreate{ID: bug.ID, Comment: fmt.Sprintf("Bug status changed to %s as previous linked PR https://github.com/%s/%s/pull/%d has been closed", options.StateAfterClose.Status, e.org, e.repo, e.number), IsPrivate: true}
1242+
bzComment := &bugzilla.CommentCreate{ID: bug.ID, Comment: fmt.Sprintf("Bug status changed to %s as previous linked PR https://%s/%s/%s/pull/%d has been closed", options.StateAfterClose.Status, github.DefaultHost, e.org, e.repo, e.number), IsPrivate: true}
12431243
if _, err := bc.CreateComment(bzComment); err != nil {
12441244
response += "\nWarning: Failed to comment on Bugzilla bug with reason for changed state."
12451245
}

pkg/plugins/dco/dco.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,15 @@ func handle(config plugins.Dco, gc gitHubClient, cp commentPruner, log *logrus.E
332332
contributingPath = config.ContributingPath
333333
}
334334

335-
contributingUrl := fmt.Sprintf("https://github.com/%s/blob/%s/%s", contributingRepo, contributingBranch, contributingPath)
335+
contributingUrl := fmt.Sprintf("https://%s/%s/blob/%s/%s", github.DefaultHost, contributingRepo, contributingBranch, contributingPath)
336336

337337
return takeAction(gc, cp, l, org, repo, pr, commitsMissingDCO, existingStatus, contributingUrl, hasYesLabel, hasNoLabel, addComment)
338338
}
339339

340340
// MarkdownSHAList prints the list of commits in a markdown-friendly way.
341341
func MarkdownSHAList(org, repo string, list []github.RepositoryCommit) string {
342342
lines := make([]string, len(list))
343-
lineFmt := "- [%s](https://github.com/%s/%s/commits/%s) %s"
343+
lineFmt := "- [%s](https://%s/%s/%s/commits/%s) %s"
344344
for i, commit := range list {
345345
if commit.SHA == "" {
346346
continue
@@ -355,7 +355,7 @@ func MarkdownSHAList(org, repo string, list []github.RepositoryCommit) string {
355355
// get the first line of the commit
356356
message := strings.Split(commit.Commit.Message, "\n")[0]
357357

358-
lines[i] = fmt.Sprintf(lineFmt, shortSHA, org, repo, commit.SHA, message)
358+
lines[i] = fmt.Sprintf(lineFmt, shortSHA, github.DefaultHost, org, repo, commit.SHA, message)
359359
}
360360
return strings.Join(lines, "\n")
361361
}

pkg/plugins/milestone/milestone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const pluginName = "milestone"
3636

3737
var (
3838
milestoneRegex = regexp.MustCompile(`(?m)^/milestone\s+(.+?)\s*$`)
39-
mustBeAuthorized = "You must be a member of the [%s/%s](https://github.com/orgs/%s/teams/%s/members) GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your %s and have them propose you as an additional delegate for this responsibility."
39+
mustBeAuthorized = "You must be a member of the [%s/%s](https://%s/orgs/%s/teams/%s/members) GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your %s and have them propose you as an additional delegate for this responsibility."
4040
invalidMilestone = "The provided milestone is not valid for this repository. Milestones in this repository: [%s]\n\nUse `/milestone %s` to clear the milestone."
4141
milestoneTeamMsg = "The milestone maintainers team is the GitHub team %q with ID: %d."
4242
clearKeyword = "clear"
@@ -127,7 +127,7 @@ func handle(gc githubClient, log *logrus.Entry, e *github.GenericCommentEvent, r
127127
}
128128
if !found {
129129
// not in the milestone maintainers team
130-
msg := fmt.Sprintf(mustBeAuthorized, org, milestone.MaintainersTeam, org, milestone.MaintainersTeam, milestone.MaintainersFriendlyName)
130+
msg := fmt.Sprintf(mustBeAuthorized, org, milestone.MaintainersTeam, github.DefaultHost, org, milestone.MaintainersTeam, milestone.MaintainersFriendlyName)
131131
return gc.CreateComment(org, repo, e.Number, plugins.FormatResponseRaw(e.Body, e.HTMLURL, e.User.Login, msg))
132132
}
133133

pkg/plugins/milestonestatus/milestonestatus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const pluginName = "milestonestatus"
3535

3636
var (
3737
statusRegex = regexp.MustCompile(`(?m)^/status\s+(.+)$`)
38-
mustBeAuthorized = "You must be a member of the [%s/%s](https://github.com/orgs/%s/teams/%s/members) GitHub team to add status labels. If you believe you should be able to issue the /status command, please contact your %s and have them propose you as an additional delegate for this responsibility."
38+
mustBeAuthorized = "You must be a member of the [%s/%s](https://%s/orgs/%s/teams/%s/members) GitHub team to add status labels. If you believe you should be able to issue the /status command, please contact your %s and have them propose you as an additional delegate for this responsibility."
3939
milestoneTeamMsg = "The milestone maintainers team is the GitHub team %q"
4040
statusMap = map[string]string{
4141
"approved-for-milestone": "status/approved-for-milestone",
@@ -121,7 +121,7 @@ func handle(gc githubClient, log *logrus.Entry, e *github.GenericCommentEvent, r
121121
}
122122
if !found {
123123
// not in the milestone maintainers team
124-
msg := fmt.Sprintf(mustBeAuthorized, org, milestone.MaintainersTeam, org, milestone.MaintainersTeam, milestone.MaintainersFriendlyName)
124+
msg := fmt.Sprintf(mustBeAuthorized, org, milestone.MaintainersTeam, github.DefaultHost, org, milestone.MaintainersTeam, milestone.MaintainersFriendlyName)
125125
return gc.CreateComment(org, repo, e.Number, msg)
126126
}
127127

pkg/plugins/projectmanager/projectmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func getMatchingColumnIDs(gc githubClient, orgRepos map[string]plugins.ManagedOr
205205
}
206206
}
207207

208-
issueURL := fmt.Sprintf("https://api.github.com/repos/%s/%s/issues/%v", e.org, e.repo, e.number)
208+
issueURL := fmt.Sprintf("%s/repos/%s/%s/issues/%v", github.DefaultAPIEndpoint, e.org, e.repo, e.number)
209209
for orgRepoName, managedOrgRepo := range orgRepos {
210210
for projectName, managedProject := range managedOrgRepo.Projects {
211211
for _, managedColumn := range managedProject.Columns {

pkg/plugins/transfer-issue/transfer-issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ type testClient struct {
202202
func (t *testClient) GetRepo(org, name string) (github.FullRepo, error) {
203203
r := []rune(name)
204204
if lastChar := r[len(r)-1]; unicode.IsSpace(lastChar) {
205-
return github.FullRepo{}, fmt.Errorf("failed creating new request: parse \"https://api.github.com/repos/%s/%s\\r\": net/url: invalid control character in URL", org, name)
205+
return github.FullRepo{}, fmt.Errorf("failed creating new request: parse \"%s/repos/%s/%s\\r\": net/url: invalid control character in URL", github.DefaultAPIEndpoint, org, name)
206206
}
207207
repo, err := t.fc.GetRepo(org, name)
208208
if len(t.repoNodeID) != 0 {

pkg/plugins/trigger/pull-request.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ func welcomeMsg(ghc githubClient, trigger plugins.Trigger, pr github.PullRequest
254254
encodedRepoFullName := url.QueryEscape(pr.Base.Repo.FullName)
255255
var more string
256256
if trigger.TrustedOrg != "" && trigger.TrustedOrg != org {
257-
more = fmt.Sprintf("or [%s](https://github.com/orgs/%s/people) ", trigger.TrustedOrg, trigger.TrustedOrg)
257+
more = fmt.Sprintf("or [%s](https://%s/orgs/%s/people) ", trigger.TrustedOrg, github.DefaultHost, trigger.TrustedOrg)
258258
}
259259

260260
var joinOrgURL string
261261
if trigger.JoinOrgURL != "" {
262262
joinOrgURL = trigger.JoinOrgURL
263263
} else {
264-
joinOrgURL = fmt.Sprintf("https://github.com/orgs/%s/people", org)
264+
joinOrgURL = fmt.Sprintf("https://%s/orgs/%s/people", github.DefaultHost, org)
265265
}
266266

267267
var comment string
@@ -280,7 +280,7 @@ I understand the commands that are listed [here](https://go.k8s.io/bot-commands?
280280
} else {
281281
comment = fmt.Sprintf(`Hi @%s. Thanks for your PR.
282282
283-
I'm waiting for a [%s](https://github.com/orgs/%s/people) %smember to verify that this patch is reasonable to test. If it is, they should reply with `+"`/ok-to-test`"+` on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should [join the org](%s) to skip this step.
283+
I'm waiting for a [%s](https://%s/orgs/%s/people) %smember to verify that this patch is reasonable to test. If it is, they should reply with `+"`/ok-to-test`"+` on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should [join the org](%s) to skip this step.
284284
285285
Once the patch is verified, the new status will be reflected by the `+"`%s`"+` label.
286286
@@ -290,7 +290,7 @@ I understand the commands that are listed [here](https://go.k8s.io/bot-commands?
290290
291291
%s
292292
</details>
293-
`, author, org, org, more, joinOrgURL, labels.OkToTest, encodedRepoFullName, plugins.AboutThisBotWithoutCommands)
293+
`, author, github.DefaultHost, org, org, more, joinOrgURL, labels.OkToTest, encodedRepoFullName, plugins.AboutThisBotWithoutCommands)
294294

295295
l, err := ghc.GetIssueLabels(org, repo, pr.Number)
296296
if err != nil {

pkg/plugins/verify-owners/verify-owners.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func handle(ghc githubClient, gc git.ClientFactory, roc repoownersClient, log *l
364364
if triggerConfig.JoinOrgURL != "" {
365365
joinOrgURL = triggerConfig.JoinOrgURL
366366
} else {
367-
joinOrgURL = fmt.Sprintf("https://github.com/orgs/%s/people", org)
367+
joinOrgURL = fmt.Sprintf("https://%s/orgs/%s/people", github.DefaultHost, org)
368368
}
369369

370370
if len(nonTrustedUsers) > 0 {

pkg/pod-utils/clone/clone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func PathForRefs(baseDir string, refs prowapi.Refs) string {
145145
parts := strings.Split(refs.RepoLink, "://")
146146
clonePath = parts[len(parts)-1]
147147
} else {
148-
clonePath = fmt.Sprintf("github.com/%s/%s", refs.Org, refs.Repo)
148+
clonePath = fmt.Sprintf("%s/%s/%s", github.DefaultHost, refs.Org, refs.Repo)
149149
}
150150
return path.Join(baseDir, "src", clonePath)
151151
}
@@ -163,7 +163,7 @@ func gitCtxForRefs(refs prowapi.Refs, baseDir string, env []string, user, token
163163
if refs.RepoLink != "" {
164164
repoURI = fmt.Sprintf("%s.git", refs.RepoLink)
165165
} else {
166-
repoURI = fmt.Sprintf("https://github.com/%s/%s.git", refs.Org, refs.Repo)
166+
repoURI = fmt.Sprintf("https://%s/%s/%s.git", github.DefaultHost, refs.Org, refs.Repo)
167167
}
168168

169169
g := gitCtx{

0 commit comments

Comments
 (0)