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: 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 5ded45c..d90eb05 100644 --- a/src/acigithub/issues.go +++ b/src/acigithub/issues.go @@ -14,16 +14,30 @@ 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, - ListOptions: github.ListOptions{ - PerPage: 100, - Page: 1, - }, + Direction: &direction, + Sort: &sort, + ListOptions: standardListOptions, } 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) { @@ -32,12 +46,9 @@ func CommentHelpToPullRequest(number int) (err error) { } var commentOpts = &github.IssueListCommentsOptions{ - Direction: &direction, - Sort: &sort, - ListOptions: github.ListOptions{ - PerPage: 30, - 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 db60ac6..28cb5dd 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,21 +75,34 @@ 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 - if strings.Contains("OWNER|CONTRIBUTOR|COLLABORATOR", *comment.AuthorAssociation) { + // 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, 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 true { 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 + } + } }