pr: add reviewers to PR workflow
This commit is contained in:
parent
3d7336a3a0
commit
a0a79dcf4d
@ -22,6 +22,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
@ -32,6 +33,7 @@ type AutogitConfig struct {
|
||||
Organization string
|
||||
GitProjectName string // Organization/GitProjectName.git is PrjGit
|
||||
Branch string // branch name of PkgGit that aligns with PrjGit submodules
|
||||
Reviewers []string // only used by `pr` workflow
|
||||
}
|
||||
|
||||
func ReadWorkflowConfigs(reader io.Reader) ([]*AutogitConfig, error) {
|
||||
@ -47,7 +49,11 @@ func ReadWorkflowConfigs(reader io.Reader) ([]*AutogitConfig, error) {
|
||||
|
||||
availableWorkflows := []string{"pr", "direct", "test"}
|
||||
for _, workflow := range config {
|
||||
pr := false
|
||||
for _, w := range workflow.Workflows {
|
||||
if w == "pr" {
|
||||
pr = true
|
||||
}
|
||||
if !slices.Contains(availableWorkflows, w) {
|
||||
return nil, fmt.Errorf(
|
||||
"Invalid Workflow '%s'. Only available workflows are: %s",
|
||||
@ -58,6 +64,12 @@ func ReadWorkflowConfigs(reader io.Reader) ([]*AutogitConfig, error) {
|
||||
if len(workflow.GitProjectName) == 0 {
|
||||
workflow.GitProjectName = DefaultGitPrj
|
||||
}
|
||||
if !pr && len(workflow.Reviewers) > 0 {
|
||||
log.Println(" Warning: non-PR-only workflows contains Reviewers. These are ignored in Org:", workflow.Organization)
|
||||
}
|
||||
if pr && !slices.Contains(workflow.Reviewers, Bot_BuildReview) {
|
||||
workflow.Reviewers = append(workflow.Reviewers, Bot_BuildReview)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
@ -27,6 +27,9 @@ JSON
|
||||
* _Organization_: organization that holds all the packages
|
||||
* _Branch_: branch updated in repo's
|
||||
* _GitProjectName_: package in above org, or `org/package` for PrjGit
|
||||
* _Reviewers_: accounts associated with mandatory reviews for PrjGit. Can trigger additional
|
||||
review requests for PrjGit or associated PkgGit repos. Only when all reviews are
|
||||
satisfied, will the PrjGit PR be merged.
|
||||
|
||||
example:
|
||||
|
||||
@ -35,7 +38,8 @@ example:
|
||||
"Workflows": ["pr", "direct"],
|
||||
"Organization": "autogits",
|
||||
"GitProjectName": "HiddenPrj",
|
||||
"Branch": "hidden"
|
||||
"Branch": "hidden",
|
||||
"Reviewers": []
|
||||
},
|
||||
...
|
||||
]
|
||||
|
@ -180,7 +180,12 @@ referencing the following pull request:
|
||||
}
|
||||
|
||||
// request build review
|
||||
_, err = gitea.RequestReviews(PR, common.Bot_BuildReview)
|
||||
for _, reviewer := range config.Reviewers {
|
||||
_, err := gitea.RequestReviews(PR, reviewer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create reviewer '%s' for request: %s/%s/%d Err: %w", reviewer, PR.Base.Repo.Owner.UserName, PR.Base.Repo.Name, PR.Index, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@ -261,7 +266,7 @@ nextSubmodule:
|
||||
}
|
||||
|
||||
if DebugMode {
|
||||
log.Println(" - # of PRs to check:" , len(prs))
|
||||
log.Println(" - # of PRs to check:", len(prs))
|
||||
}
|
||||
|
||||
for _, pr := range prs {
|
||||
|
Loading…
Reference in New Issue
Block a user