Skip to content

Commit d61aef3

Browse files
authored
Merge pull request #90 from fullstack-devops/bugfix/ET-46_version_override
fixed version override
2 parents ebe5f14 + 6499c0c commit d61aef3

4 files changed

Lines changed: 50 additions & 21 deletions

File tree

.github/workflows/branchPR.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
steps:
1919
- name: Checkout code
2020
uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
2123
- name: Set up Go
2224
uses: actions/setup-go@v2
2325
with:

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: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,30 @@ var (
1414
)
1515

1616
func GetIssueComments(issueNumber int) (issueComments []*github.IssueComment, err error) {
17+
18+
//FIXME: currently the GitHub API ignores Direction and Sort
19+
// so, we are using the default settings for the query and sorting the response afterwards
1720
var commentOpts = &github.IssueListCommentsOptions{
18-
Direction: &direction,
19-
// Sort: &sort,
20-
ListOptions: github.ListOptions{
21-
PerPage: 100,
22-
Page: 1,
23-
},
21+
Direction: &direction,
22+
Sort: &sort,
23+
ListOptions: standardListOptions,
2424
}
2525
issueComments, _, err = GithubClient.Issues.ListComments(ctx, owner, repo, issueNumber, commentOpts)
26-
return
26+
27+
if err == nil {
28+
icCount := len(issueComments)
29+
issueCommentsSorted := make([]*github.IssueComment, icCount)
30+
31+
for i, n := range issueComments {
32+
j := icCount - i - 1
33+
34+
issueCommentsSorted[j] = n
35+
}
36+
37+
return issueCommentsSorted, err
38+
}
39+
40+
return nil, err
2741
}
2842

2943
func CommentHelpToPullRequest(number int) (err error) {
@@ -32,12 +46,9 @@ func CommentHelpToPullRequest(number int) (err error) {
3246
}
3347

3448
var commentOpts = &github.IssueListCommentsOptions{
35-
Direction: &direction,
36-
Sort: &sort,
37-
ListOptions: github.ListOptions{
38-
PerPage: 30,
39-
Page: 1,
40-
},
49+
Direction: &direction,
50+
Sort: &sort,
51+
ListOptions: standardListOptions,
4152
}
4253
comments, _, err := GithubClient.Issues.ListComments(ctx, owner, repo, number, commentOpts)
4354
if err != nil {

src/acigithub/pullrequest.go

Lines changed: 20 additions & 8 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,21 +75,34 @@ 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-
if strings.Contains("OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) {
80+
// FIXME: access must be restricted but GITHUB_TOKEN doesn't get informations.
81+
// Refs: https://docs.github.com/en/rest/collaborators/collaborators#list-repository-collaborators
82+
// Refs: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
83+
84+
// Must be a collaborator to have permission to create an override
85+
// isCollaborator, resp, err := GithubClient.Repositories.IsCollaborator(ctx, owner, repo, *comment.User.Login)
86+
// if err != nil {
87+
// return nil, nil, err
88+
// }
89+
// fmt.Println(resp.StatusCode)
90+
91+
// if isCollaborator {
92+
if true {
8393
aciVersionOverride := regexp.MustCompile(`aci_version_override: ([0-9]+\.[0-9]+\.[0-9]+)`)
8494
aciPatchLevel := regexp.MustCompile(`aci_patch_level: ([a-zA-Z]+)`)
8595

86-
if aciPatchLevel.MatchString(*comment.Body) {
87-
patchLevel = semver.ParsePatchLevel(aciPatchLevel.FindStringSubmatch(*comment.Body)[1])
88-
break
89-
}
9096
if aciVersionOverride.MatchString(*comment.Body) {
9197
version = aciVersionOverride.FindStringSubmatch(*comment.Body)[1]
9298
break
9399
}
100+
101+
if aciPatchLevel.MatchString(*comment.Body) {
102+
patchLevel = semver.ParsePatchLevel(aciPatchLevel.FindStringSubmatch(*comment.Body)[1])
103+
break
104+
}
105+
94106
}
95107
}
96108

0 commit comments

Comments
 (0)