Skip to content

Commit 2eeac75

Browse files
committed
add check for collaborator
1 parent 59149c6 commit 2eeac75

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/acigithub/github-client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ var (
1818
githubRepository, isgithubRepository = os.LookupEnv("GITHUB_REPOSITORY")
1919
githubToken, isgithubToken = os.LookupEnv("GITHUB_TOKEN")
2020
owner, repo string
21+
standardListOptions = github.ListOptions{
22+
PerPage: 100,
23+
Page: 1,
24+
}
2125
)
2226

2327
// NewGitHubClient Creates a new GitHub Client

src/acigithub/issues.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ func GetIssueComments(issueNumber int) (issueComments []*github.IssueComment, er
1818
//FIXME: currently the GitHub API ignores Direction and Sort
1919
// so, we are using the default settings for the query and sorting the response afterwards
2020
var commentOpts = &github.IssueListCommentsOptions{
21-
Direction: &direction,
22-
Sort: &sort,
23-
ListOptions: github.ListOptions{
24-
PerPage: 100,
25-
Page: 1,
26-
},
21+
Direction: &direction,
22+
Sort: &sort,
23+
ListOptions: standardListOptions,
2724
}
2825
issueComments, _, err = GithubClient.Issues.ListComments(ctx, owner, repo, issueNumber, commentOpts)
2926

@@ -49,12 +46,9 @@ func CommentHelpToPullRequest(number int) (err error) {
4946
}
5047

5148
var commentOpts = &github.IssueListCommentsOptions{
52-
Direction: &direction,
53-
Sort: &sort,
54-
ListOptions: github.ListOptions{
55-
PerPage: 100,
56-
Page: 1,
57-
},
49+
Direction: &direction,
50+
Sort: &sort,
51+
ListOptions: standardListOptions,
5852
}
5953
comments, _, err := GithubClient.Issues.ListComments(ctx, owner, repo, number, commentOpts)
6054
if err != nil {

src/acigithub/pullrequest.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"log"
99
"os"
1010
"regexp"
11-
"strings"
1211

1312
"github.com/google/go-github/v39/github"
1413
)
@@ -76,13 +75,15 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St
7675
if err != nil {
7776
return nil, nil, err
7877
}
78+
7979
for _, comment := range issueComments {
80-
// Must have permission in the repo to create a major version
81-
// MANNEQUIN|NONE https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
82-
log.Println(*comment.AuthorAssociation)
83-
log.Println(*comment.Body)
84-
log.Println(*comment.User)
85-
if strings.Contains("MEMBER|OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) {
80+
// Must be a collaborator to have permission to create an override
81+
isCollaborator, _, err := GithubClient.Repositories.IsCollaborator(ctx, owner, repo, *comment.User.Login)
82+
if err != nil {
83+
return nil, nil, err
84+
}
85+
86+
if isCollaborator {
8687
aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`)
8788
aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`)
8889

0 commit comments

Comments
 (0)