staging: fixes

This commit is contained in:
2025-05-04 20:45:33 +02:00
parent 62a597718b
commit 0d0fcef7ac
4 changed files with 64 additions and 15 deletions

View File

@@ -61,7 +61,7 @@ func TestGitClone(t *testing.T) {
d := t.TempDir() d := t.TempDir()
os.Chdir(d) os.Chdir(d)
defer os.Chdir(execPath) 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 { if _, err := cmd.Output(); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@@ -85,13 +85,19 @@ type GiteaReviewFetcher interface {
GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error) GetPullRequestReviews(org, project string, PRnum int64) ([]*models.PullReview, error)
} }
type GiteaCommentFetcher interface {
GetIssueComments(org, project string, issueNo int64) ([]*models.Comment, error)
}
type GiteaPRChecker interface { type GiteaPRChecker interface {
GiteaReviewFetcher GiteaReviewFetcher
GiteaCommentFetcher
GiteaMaintainershipReader GiteaMaintainershipReader
} }
type GiteaReviewFetcherAndRequester interface { type GiteaReviewFetcherAndRequester interface {
GiteaReviewFetcher GiteaReviewFetcher
GiteaCommentFetcher
GiteaReviewRequester GiteaReviewRequester
} }
@@ -139,6 +145,7 @@ type Gitea interface {
GiteaReviewer GiteaReviewer
GiteaPRFetcher GiteaPRFetcher
GiteaReviewFetcher GiteaReviewFetcher
GiteaCommentFetcher
GiteaMaintainershipReader GiteaMaintainershipReader
GiteaFileContentReader GiteaFileContentReader
@@ -242,6 +249,30 @@ func (gitea *GiteaTransport) GetPullRequestReviews(org, project string, PRnum in
return allReviews, nil 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) { func (gitea *GiteaTransport) GetPullNotifications(since *time.Time) ([]*models.NotificationThread, error) {
bigLimit := int64(100000) bigLimit := int64(100000)

View File

@@ -41,7 +41,7 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
l.UpdateTopics() l.UpdateTopics()
if len(l.topicSubChanges) != len(test.topicDelta) { if len(l.topicSubChanges) != len(test.topicDelta) {
t.Fatal("topicSubChanges != topicDelta") t.Fatal("topicSubChanges", len(l.topicSubChanges), " != topicDelta", len(test.topicDelta))
} }
}) })
} }

View File

@@ -535,7 +535,7 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) error {
// jobs of review team to deal with issues // 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{} 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 { if err != nil {
common.LogError("Staging config", common.StagingConfigFile, "not found in PR to the project. Aborting.") common.LogError("Staging config", common.StagingConfigFile, "not found in PR to the project. Aborting.")
if !IsDryRun { 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) 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) common.LogError("Cannot find reference project for PR#", pr.Index)
if !IsDryRun { if !IsDryRun {
_, err := gitea.AddReviewComment(pr, common.ReviewStateRequestChanges, "Cannot find reference project") _, 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 != "" { if stagingConfig.StagingProject != "" {
// staging project must either be nothing or be *under* the target project. // staging project must either be nothing or be *under* the target project.
// other setups are currently not supported // 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) l := len(stagingConfig.ObsProject)
if l >= len(stagingConfig.StagingProject) || stagingConfig.ObsProject != stagingConfig.StagingProject[0:l] { if l >= len(stagingConfig.StagingProject) || stagingConfig.ObsProject != stagingConfig.StagingProject[0:l] {
common.LogError("StagingProject (", stagingConfig.StagingProject, ") is not child of target project", stagingConfig.ObsProject) 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 rebuild_all := false || stagingConfig.RebuildAll
reviews, err := gitea.GetPullRequestReviews(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index) reviews, err := gitea.GetPullRequestReviews(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index)
common.LogDebug("num reviews:", len(reviews))
if err == nil { 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: done:
for _, r := range reviews { for _, r := range reviews {
for _, l := range common.SplitLines(r.Body) { 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 { } else {
common.LogError(err) common.LogError(err)
} }
if !rebuild_all { if !rebuild_all {
_, err = gitea.AddReviewComment(pr, common.ReviewStateComment, "No package changes. Not rebuilding project by default")
common.LogInfo("No package changes detected. Ignoring") 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 return err
} }
} }