staging: fixes
This commit is contained in:
@@ -61,7 +61,7 @@ func TestGitClone(t *testing.T) {
|
||||
d := t.TempDir()
|
||||
os.Chdir(d)
|
||||
defer os.Chdir(execPath)
|
||||
cmd := exec.Command("/usr/bin/bash", path.Join(execPath, "test_clone_setup.sh"))
|
||||
cmd := exec.Command(path.Join(execPath, "test_clone_setup.sh"))
|
||||
if _, err := cmd.Output(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -85,13 +85,19 @@ type GiteaReviewFetcher interface {
|
||||
GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error)
|
||||
}
|
||||
|
||||
type GiteaCommentFetcher interface {
|
||||
GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error)
|
||||
}
|
||||
|
||||
type GiteaPRChecker interface {
|
||||
GiteaReviewFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaMaintainershipReader
|
||||
}
|
||||
|
||||
type GiteaReviewFetcherAndRequester interface {
|
||||
GiteaReviewFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaReviewRequester
|
||||
}
|
||||
|
||||
@@ -139,6 +145,7 @@ type Gitea interface {
|
||||
GiteaReviewer
|
||||
GiteaPRFetcher
|
||||
GiteaReviewFetcher
|
||||
GiteaCommentFetcher
|
||||
GiteaMaintainershipReader
|
||||
GiteaFileContentReader
|
||||
|
||||
@@ -242,6 +249,30 @@ func (gitea *GiteaTransport) GetPullRequestReviews(org, project string, PRnum in
|
||||
return allReviews, nil
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error) {
|
||||
// limit := int64(20)
|
||||
// var page int64
|
||||
// var allComments []*models.Comment
|
||||
|
||||
// for {
|
||||
c, err := gitea.client.Issue.IssueGetComments(
|
||||
issue.NewIssueGetCommentsParams().
|
||||
WithDefaults().
|
||||
WithOwner(org).
|
||||
WithRepo(project).
|
||||
WithIndex(issueNo),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.Payload, nil
|
||||
// if len(c.Payload) < int(limit)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error) {
|
||||
bigLimit := int64(100000)
|
||||
|
||||
@@ -618,13 +649,13 @@ func (gitea *GiteaTransport) GetRecentCommits(org, repo, branch string, commitNo
|
||||
not := false
|
||||
var page int64 = 1
|
||||
params := repository.NewRepoGetAllCommitsParams().
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithPage(&page).
|
||||
WithStat(¬).
|
||||
WithFiles(¬).
|
||||
WithVerification(¬).
|
||||
WithLimit(&commitNo)
|
||||
WithOwner(org).
|
||||
WithRepo(repo).
|
||||
WithPage(&page).
|
||||
WithStat(¬).
|
||||
WithFiles(¬).
|
||||
WithVerification(¬).
|
||||
WithLimit(&commitNo)
|
||||
|
||||
if len(branch) > 0 {
|
||||
params = params.WithSha(&branch)
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
||||
|
||||
l.UpdateTopics()
|
||||
if len(l.topicSubChanges) != len(test.topicDelta) {
|
||||
t.Fatal("topicSubChanges != topicDelta")
|
||||
t.Fatal("topicSubChanges", len(l.topicSubChanges), " != topicDelta", len(test.topicDelta))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -533,9 +533,9 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
|
||||
|
||||
// we want the possibly pending modification here, in case stagings are added, etc.
|
||||
// jobs of review team to deal with issues
|
||||
common.LogDebug("QA configuration fetching ...", common.StagingConfigFile )
|
||||
common.LogDebug("QA configuration fetching ...", common.StagingConfigFile)
|
||||
QA := []common.QAConfig{}
|
||||
data, err := git.GitCatFile(dir, pr.Head.Sha, common.StagingConfigFile)
|
||||
data, err := git.GitCatFile(pr.Head.Sha, pr.Head.Sha, common.StagingConfigFile)
|
||||
if err != nil {
|
||||
common.LogError("Staging config", common.StagingConfigFile, "not found in PR to the project. Aborting.")
|
||||
if !IsDryRun {
|
||||
@@ -549,7 +549,7 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
|
||||
common.LogError("Error parsing config file", common.StagingConfigFile, err)
|
||||
}
|
||||
|
||||
if stagingConfig.ObsProject != "" {
|
||||
if stagingConfig.ObsProject == "" {
|
||||
common.LogError("Cannot find reference project for PR#", pr.Index)
|
||||
if !IsDryRun {
|
||||
_, err := gitea.AddReviewComment(pr, common.ReviewStateRequestChanges, "Cannot find reference project")
|
||||
@@ -591,7 +591,7 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
|
||||
if stagingConfig.StagingProject != "" {
|
||||
// staging project must either be nothing or be *under* the target project.
|
||||
// other setups are currently not supported
|
||||
// NOTE: this is user input!!
|
||||
// NOTE: this is user input, so we need some limits here
|
||||
l := len(stagingConfig.ObsProject)
|
||||
if l >= len(stagingConfig.StagingProject) || stagingConfig.ObsProject != stagingConfig.StagingProject[0:l] {
|
||||
common.LogError("StagingProject (", stagingConfig.StagingProject, ") is not child of target project", stagingConfig.ObsProject)
|
||||
@@ -632,8 +632,9 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
|
||||
rebuild_all := false || stagingConfig.RebuildAll
|
||||
|
||||
reviews, err := gitea.GetPullRequestReviews(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index)
|
||||
common.LogDebug("num reviews:", len(reviews))
|
||||
if err == nil {
|
||||
rebuild_rx := regexp.MustCompile("^staging-bot\\s*:\\s*build\\s*all$")
|
||||
rebuild_rx := regexp.MustCompile("^@autogits_obs_staging_bot\\s*:\\s*(re)?build\\s*all$")
|
||||
done:
|
||||
for _, r := range reviews {
|
||||
for _, l := range common.SplitLines(r.Body) {
|
||||
@@ -643,13 +644,30 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
comments, err := gitea.GetIssueComments(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index)
|
||||
common.LogDebug("num comments:", len(comments))
|
||||
if err == nil {
|
||||
done2:
|
||||
for _, r := range comments {
|
||||
|
||||
for _, l := range common.SplitLines(r.Body) {
|
||||
if rebuild_rx.MatchString(strings.ToLower(l)) {
|
||||
rebuild_all = true
|
||||
break done2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
common.LogError(err)
|
||||
}
|
||||
|
||||
if !rebuild_all {
|
||||
_, err = gitea.AddReviewComment(pr, common.ReviewStateComment, "No package changes. Not rebuilding project by default")
|
||||
common.LogInfo("No package changes detected. Ignoring")
|
||||
if !IsDryRun {
|
||||
_, err = gitea.AddReviewComment(pr, common.ReviewStateComment, "No package changes. Not rebuilding project by default")
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user