From a611a01c417bc45a65c65058f7d61954829120c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Hie=C3=9F?= Date: Mon, 11 Apr 2022 08:26:30 +0200 Subject: [PATCH 1/7] fixed version override --- src/acigithub/issues.go | 23 ++++++++++++++++++++--- src/acigithub/pullrequest.go | 12 +++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/acigithub/issues.go b/src/acigithub/issues.go index 5ded45c..89d4c6e 100644 --- a/src/acigithub/issues.go +++ b/src/acigithub/issues.go @@ -14,16 +14,33 @@ var ( ) func GetIssueComments(issueNumber int) (issueComments []*github.IssueComment, err error) { + + //FIXME: currently the GitHub API ignores Direction and Sort + // so, we are using the default settings for the query and sorting the response afterwards var commentOpts = &github.IssueListCommentsOptions{ Direction: &direction, - // Sort: &sort, + Sort: &sort, ListOptions: github.ListOptions{ PerPage: 100, Page: 1, }, } issueComments, _, err = GithubClient.Issues.ListComments(ctx, owner, repo, issueNumber, commentOpts) - return + + if err == nil { + icCount := len(issueComments) + issueCommentsSorted := make([]*github.IssueComment, icCount) + + for i, n := range issueComments { + j := icCount - i - 1 + + issueCommentsSorted[j] = n + } + + return issueCommentsSorted, err + } + + return nil, err } func CommentHelpToPullRequest(number int) (err error) { @@ -35,7 +52,7 @@ func CommentHelpToPullRequest(number int) (err error) { Direction: &direction, Sort: &sort, ListOptions: github.ListOptions{ - PerPage: 30, + PerPage: 100, Page: 1, }, } diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index db60ac6..eb428ca 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -79,18 +79,20 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St for _, comment := range issueComments { // Must have permission in the repo to create a major version // MANNEQUIN|NONE https://docs.github.com/en/graphql/reference/enums#commentauthorassociation - if strings.Contains("OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { + if strings.Contains("MEMBER|OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`) aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`) - if aciPatchLevel.MatchString(*comment.Body) { - patchLevel = semver.ParsePatchLevel(aciPatchLevel.FindStringSubmatch(*comment.Body)[1]) - break - } if aciVersionOverride.MatchString(*comment.Body) { version = aciVersionOverride.FindStringSubmatch(*comment.Body)[1] break } + + if aciPatchLevel.MatchString(*comment.Body) { + patchLevel = semver.ParsePatchLevel(aciPatchLevel.FindStringSubmatch(*comment.Body)[1]) + break + } + } } From a0c358d2a213db5ae5218b0ca93158b293e276c6 Mon Sep 17 00:00:00 2001 From: eksrha <58111764+eksrha@users.noreply.github.com> Date: Tue, 12 Apr 2022 18:22:47 +0200 Subject: [PATCH 2/7] debug --- src/acigithub/pullrequest.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index eb428ca..11cb08b 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -79,12 +79,16 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St for _, comment := range issueComments { // Must have permission in the repo to create a major version // MANNEQUIN|NONE https://docs.github.com/en/graphql/reference/enums#commentauthorassociation + log.Println(comment.AuthorAssociation) + log.Println(comment.Body) + log.Println(comment.User) if strings.Contains("MEMBER|OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`) aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`) if aciVersionOverride.MatchString(*comment.Body) { version = aciVersionOverride.FindStringSubmatch(*comment.Body)[1] + log.Println("Found a veriosn override") break } From 2089159896fc6da1d5334cdf9d55ebfc1ad3fdaa Mon Sep 17 00:00:00 2001 From: eksrha <58111764+eksrha@users.noreply.github.com> Date: Tue, 12 Apr 2022 18:25:56 +0200 Subject: [PATCH 3/7] add full checkout to workflow build --- .github/workflows/branchPR.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/branchPR.yaml b/.github/workflows/branchPR.yaml index a418f71..95672ab 100644 --- a/.github/workflows/branchPR.yaml +++ b/.github/workflows/branchPR.yaml @@ -18,6 +18,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v2 with: From 59149c6c2693b484987b2f060f08dea46028c6be Mon Sep 17 00:00:00 2001 From: eksrha <58111764+eksrha@users.noreply.github.com> Date: Tue, 12 Apr 2022 18:29:17 +0200 Subject: [PATCH 4/7] debug issue infos --- src/acigithub/pullrequest.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index 11cb08b..c0ced45 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -79,9 +79,9 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St for _, comment := range issueComments { // Must have permission in the repo to create a major version // MANNEQUIN|NONE https://docs.github.com/en/graphql/reference/enums#commentauthorassociation - log.Println(comment.AuthorAssociation) - log.Println(comment.Body) - log.Println(comment.User) + log.Println(*comment.AuthorAssociation) + log.Println(*comment.Body) + log.Println(*comment.User) if strings.Contains("MEMBER|OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`) aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`) From 2eeac7532863854139d626e44c8381174515eb90 Mon Sep 17 00:00:00 2001 From: eksrha <58111764+eksrha@users.noreply.github.com> Date: Tue, 12 Apr 2022 19:21:29 +0200 Subject: [PATCH 5/7] add check for collaborator --- src/acigithub/github-client.go | 4 ++++ src/acigithub/issues.go | 18 ++++++------------ src/acigithub/pullrequest.go | 15 ++++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/acigithub/github-client.go b/src/acigithub/github-client.go index 146813e..79f6e5b 100644 --- a/src/acigithub/github-client.go +++ b/src/acigithub/github-client.go @@ -18,6 +18,10 @@ var ( githubRepository, isgithubRepository = os.LookupEnv("GITHUB_REPOSITORY") githubToken, isgithubToken = os.LookupEnv("GITHUB_TOKEN") owner, repo string + standardListOptions = github.ListOptions{ + PerPage: 100, + Page: 1, + } ) // NewGitHubClient Creates a new GitHub Client diff --git a/src/acigithub/issues.go b/src/acigithub/issues.go index 89d4c6e..d90eb05 100644 --- a/src/acigithub/issues.go +++ b/src/acigithub/issues.go @@ -18,12 +18,9 @@ func GetIssueComments(issueNumber int) (issueComments []*github.IssueComment, er //FIXME: currently the GitHub API ignores Direction and Sort // so, we are using the default settings for the query and sorting the response afterwards var commentOpts = &github.IssueListCommentsOptions{ - Direction: &direction, - Sort: &sort, - ListOptions: github.ListOptions{ - PerPage: 100, - Page: 1, - }, + Direction: &direction, + Sort: &sort, + ListOptions: standardListOptions, } issueComments, _, err = GithubClient.Issues.ListComments(ctx, owner, repo, issueNumber, commentOpts) @@ -49,12 +46,9 @@ func CommentHelpToPullRequest(number int) (err error) { } var commentOpts = &github.IssueListCommentsOptions{ - Direction: &direction, - Sort: &sort, - ListOptions: github.ListOptions{ - PerPage: 100, - Page: 1, - }, + Direction: &direction, + Sort: &sort, + ListOptions: standardListOptions, } comments, _, err := GithubClient.Issues.ListComments(ctx, owner, repo, number, commentOpts) if err != nil { diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index c0ced45..f24d152 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -8,7 +8,6 @@ import ( "log" "os" "regexp" - "strings" "github.com/google/go-github/v39/github" ) @@ -76,13 +75,15 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St if err != nil { return nil, nil, err } + for _, comment := range issueComments { - // Must have permission in the repo to create a major version - // MANNEQUIN|NONE https://docs.github.com/en/graphql/reference/enums#commentauthorassociation - log.Println(*comment.AuthorAssociation) - log.Println(*comment.Body) - log.Println(*comment.User) - if strings.Contains("MEMBER|OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { + // Must be a collaborator to have permission to create an override + isCollaborator, _, err := GithubClient.Repositories.IsCollaborator(ctx, owner, repo, *comment.User.Login) + if err != nil { + return nil, nil, err + } + + if isCollaborator { aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`) aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`) From e201c1c2c5a748ef41baef78f7c5b8f30fa900fe Mon Sep 17 00:00:00 2001 From: eksrha <58111764+eksrha@users.noreply.github.com> Date: Tue, 12 Apr 2022 19:21:49 +0200 Subject: [PATCH 6/7] add check for collaborator --- src/acigithub/pullrequest.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index f24d152..72bae33 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -89,7 +89,6 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St if aciVersionOverride.MatchString(*comment.Body) { version = aciVersionOverride.FindStringSubmatch(*comment.Body)[1] - log.Println("Found a veriosn override") break } From 6499c0c6ab7a0cbce75e1609f471235cae4ef39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eike=20S=C3=B6ren=20Haller?= Date: Fri, 22 Apr 2022 09:33:18 +0200 Subject: [PATCH 7/7] disable permissioncheck override --- src/acigithub/pullrequest.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/acigithub/pullrequest.go b/src/acigithub/pullrequest.go index 72bae33..28cb5dd 100644 --- a/src/acigithub/pullrequest.go +++ b/src/acigithub/pullrequest.go @@ -77,13 +77,19 @@ func GetPrInfos(prNumber int, mergeCommitSha string) (standardPrInfos *models.St } for _, comment := range issueComments { + // FIXME: access must be restricted but GITHUB_TOKEN doesn't get informations. + // Refs: https://docs.github.com/en/rest/collaborators/collaborators#list-repository-collaborators + // Refs: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token + // Must be a collaborator to have permission to create an override - isCollaborator, _, err := GithubClient.Repositories.IsCollaborator(ctx, owner, repo, *comment.User.Login) - if err != nil { - return nil, nil, err - } + // isCollaborator, resp, err := GithubClient.Repositories.IsCollaborator(ctx, owner, repo, *comment.User.Login) + // if err != nil { + // return nil, nil, err + // } + // fmt.Println(resp.StatusCode) - if isCollaborator { + // if isCollaborator { + if true { aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`) aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`)