Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/branchPR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/acigithub/github-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 24 additions & 13 deletions src/acigithub/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
28 changes: 20 additions & 8 deletions src/acigithub/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"
"os"
"regexp"
"strings"

"github.com/google/go-github/v39/github"
)
Expand Down Expand Up @@ -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
}

}
}

Expand Down