Skip to content

Commit e025455

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/go-git/go-git/v5-5.13.0
2 parents 83190ee + 30f4c4a commit e025455

212 files changed

Lines changed: 56497 additions & 20829 deletions

File tree

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ repos:
1010
language: golang
1111
pass_filenames: false
1212

13-
- repo: https://github.com/dnephin/pre-commit-golang
14-
rev: v0.3.3
15-
hooks:
16-
- id: go-unit-tests
13+
# Run as part of GHA workflow
14+
# - repo: https://github.com/dnephin/pre-commit-golang
15+
# rev: v0.3.3
16+
# hooks:
17+
# - id: go-unit-tests
1718

1819
- repo: local
1920
hooks:

.secrets.example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Save as .secrets for testing with nektos/act
22

33
LD_ACCESS_TOKEN= # LaunchDarkly access token
4+
LD_ACCESS_TOKEN_WRITER= # LaunchDarkly access token (both are used for local runs with act)
45
GITHUB_TOKEN= # GitHub PAT with repo access

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66

77
### Fixed
88

9+
## 2.1.0
10+
11+
### Added
12+
13+
- Add support for enterprise hosted github instances [More info](https://github.com/launchdarkly/find-code-references-in-pull-request/issues/102)
14+
15+
### Changed
16+
17+
### Fixed
18+
19+
- Potential null pointer error when creating flag links
20+
21+
## 2.0.2
22+
23+
### Changed
24+
25+
- Update dependencies
26+
927
## 2.0.1
1028

1129
### Changed

DEVELOPMENT.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
## Testing locally
1010

1111
Use [nektos/act](https://github.com/nektos/act) to run actions locally.
12+
NB: You'll want to use the `large` runner in order to have access to all commands needed for testing.
1213

1314
```
14-
act
15+
act -e testdata/act/pull-request.json
1516
```
1617

1718
_Read more: [Example commands](https://github.com/nektos/act#example-commands)_

comments/comments.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414

1515
sprig "github.com/Masterminds/sprig/v3"
1616

17-
"github.com/google/go-github/github"
17+
"github.com/google/go-github/v68/github"
18+
1819
ldapi "github.com/launchdarkly/api-client-go/v15"
1920
lcr "github.com/launchdarkly/find-code-references-in-pull-request/config"
2021
gha "github.com/launchdarkly/find-code-references-in-pull-request/internal/github_actions"

config/config.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"strconv"
88
"strings"
99

10-
"github.com/google/go-github/github"
10+
"github.com/google/go-github/v68/github"
11+
1112
"golang.org/x/oauth2"
1213

1314
gha "github.com/launchdarkly/find-code-references-in-pull-request/internal/github_actions"
@@ -97,14 +98,27 @@ func ValidateInputandParse(ctx context.Context) (*Config, error) {
9798
config.CreateFlagLinks = createFlagLinks
9899
}
99100

100-
config.GHClient = getGithubClient(ctx)
101+
client, err := getGithubClient(ctx)
102+
if err != nil {
103+
return nil, err
104+
}
105+
config.GHClient = client
106+
101107
return &config, nil
102108
}
103109

104-
func getGithubClient(ctx context.Context) *github.Client {
110+
func getGithubClient(ctx context.Context) (*github.Client, error) {
105111
ts := oauth2.StaticTokenSource(
106112
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
107113
)
108114
tc := oauth2.NewClient(ctx, ts)
109-
return github.NewClient(tc)
115+
gc := github.NewClient(tc)
116+
117+
host := os.Getenv("GITHUB_SERVER_URL")
118+
if host != "https://github.com" && host != "" {
119+
gha.Log("Using GitHub Enterprise host. baseUrl: %s, uploadUrl: %s", host+"/api/v3/", host+"/api/uploads/")
120+
return gc.WithEnterpriseURLs(host+"/api/v3/", host+"/api/uploads/")
121+
}
122+
123+
return gc, nil
110124
}

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/launchdarkly/find-code-references-in-pull-request
22

3-
go 1.22
4-
toolchain go1.22.5
3+
go 1.22.0
4+
5+
toolchain go1.22.7
56

67
require (
78
github.com/Masterminds/sprig/v3 v3.3.0
8-
github.com/google/go-github v17.0.0+incompatible
9-
github.com/google/go-querystring v1.0.0 // indirect
9+
github.com/google/go-querystring v1.1.0 // indirect
1010
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
1111
github.com/sourcegraph/go-diff v0.6.1
1212
github.com/spf13/viper v1.19.0
@@ -15,6 +15,7 @@ require (
1515
)
1616

1717
require (
18+
github.com/google/go-github/v68 v68.0.0
1819
github.com/jstemmer/go-junit-report/v2 v2.1.0
1920
github.com/kyoh86/richgo v0.3.12
2021
github.com/launchdarkly/ld-find-code-refs/v2 v2.13.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
107107
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
108108
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
109109
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
110-
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
111-
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
110+
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
111+
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
112+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
113+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
112114
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
113115
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
114116
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=

internal/ldclient/flag_links.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/google/go-github/github"
12+
"github.com/google/go-github/v68/github"
13+
1314
ldapi "github.com/launchdarkly/api-client-go/v15"
1415
lcr "github.com/launchdarkly/find-code-references-in-pull-request/config"
1516
gha "github.com/launchdarkly/find-code-references-in-pull-request/internal/github_actions"
17+
"github.com/launchdarkly/find-code-references-in-pull-request/internal/utils"
1618
"github.com/launchdarkly/find-code-references-in-pull-request/internal/version"
1719

1820
flags "github.com/launchdarkly/find-code-references-in-pull-request/internal/references"
@@ -100,23 +102,24 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
100102
return nil
101103
}
102104

105+
authorLogin := utils.SafeString(pr.User.Login)
103106
metadata := map[string]string{
104107
"message": message,
105108
"prNumber": strconv.Itoa(*pr.Number),
106-
"prTitle": *pr.Title,
107-
"prBody": *pr.Body,
108-
"state": *pr.State,
109-
"avatarUrl": *pr.User.AvatarURL,
110-
"repoName": *event.Repo.FullName,
111-
"repoUrl": *event.Repo.HTMLURL,
109+
"prTitle": utils.SafeString(pr.Title),
110+
"prBody": utils.SafeString(pr.Body),
111+
"state": utils.SafeString(pr.State),
112+
"avatarUrl": utils.SafeString(pr.User.AvatarURL),
113+
"repoName": utils.SafeString(event.Repo.FullName),
114+
"repoUrl": utils.SafeString(event.Repo.HTMLURL),
112115
}
113116

114117
if pr.User.Name != nil {
115-
metadata["authorName"] = *pr.User.Name
116-
metadata["authorDisplayName"] = *pr.User.Name
118+
metadata["authorName"] = utils.SafeString(pr.User.Name)
119+
metadata["authorDisplayName"] = utils.SafeString(pr.User.Name)
117120
} else {
118-
metadata["authorDisplayName"] = *pr.User.Login
119-
metadata["authorLogin"] = *pr.User.Login
121+
metadata["authorDisplayName"] = authorLogin
122+
metadata["authorLogin"] = authorLogin
120123
}
121124

122125
var timestamp *int64
@@ -130,25 +133,30 @@ func makeFlagLinkRep(event *github.PullRequestEvent, flagKey, message string) *l
130133
// key must be unique
131134
key := fmt.Sprintf("github-pr-%s-%s", id, flagKey)
132135

136+
description := utils.SafeString(pr.Body)
137+
// Flag links require a description
138+
if description == "" {
139+
description = "Empty PR Body"
140+
}
133141
return &ldapi.FlagLinkPost{
134142
DeepLink: pr.HTMLURL,
135143
Key: &key,
136144
IntegrationKey: &integration,
137145
Timestamp: timestamp,
138146
Title: getLinkTitle(event),
139-
Description: pr.Body,
147+
Description: &description,
140148
Metadata: &metadata,
141149
}
142150
}
143151

144152
func getLinkTitle(event *github.PullRequestEvent) *string {
145153
builder := new(strings.Builder)
146-
builder.WriteString(fmt.Sprintf("[%s]", *event.Repo.FullName))
154+
builder.WriteString(fmt.Sprintf("[%s]", utils.SafeString(event.Repo.FullName)))
147155

148156
pr := event.PullRequest
149157
if pr.Title != nil {
150158
builder.WriteString(" ")
151-
builder.WriteString(*pr.Title)
159+
builder.WriteString(utils.SafeString(pr.Title))
152160
if pr.Number != nil {
153161
builder.WriteString(fmt.Sprintf(" (#%d)", *pr.Number))
154162
}

internal/utils/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ func Dedupe(s []string) []string {
1414
}
1515
return ret
1616
}
17+
18+
func SafeString(s *string) string {
19+
if s != nil {
20+
return *s
21+
}
22+
return ""
23+
}

0 commit comments

Comments
 (0)