forked from adamm/autogits
Compare commits
6 Commits
Author | SHA256 | Date | |
---|---|---|---|
f2089f99fc | |||
10ea3a8f8f | |||
9faa6ead49 | |||
29cce5741a | |||
804e542c3f | |||
72899162b0 |
@@ -322,10 +322,13 @@ func GenerateObsPrjMeta(git common.Git, gitea common.Gitea, pr *models.PullReque
|
||||
urlPkg = append(urlPkg, "onlybuild="+url.QueryEscape(pkg))
|
||||
}
|
||||
meta.ScmSync = pr.Head.Repo.CloneURL + "?" + strings.Join(urlPkg, "&") + "#" + pr.Head.Sha
|
||||
if len(meta.ScmSync) >= 65535 {
|
||||
return nil, errors.New("Reached max amount of package changes per request")
|
||||
}
|
||||
meta.Title = fmt.Sprintf("PR#%d to %s", pr.Index, pr.Base.Name)
|
||||
// QE wants it published ... also we should not hardcode it here, since
|
||||
// it is configurable via the :PullRequest project
|
||||
// meta.PublicFlags = common.Flags{Contents: "<disable/>"}
|
||||
// QE wants it published ... also we should not hardcode it here, since
|
||||
// it is configurable via the :PullRequest project
|
||||
// meta.PublicFlags = common.Flags{Contents: "<disable/>"}
|
||||
|
||||
meta.Groups = nil
|
||||
meta.Persons = nil
|
||||
@@ -633,6 +636,14 @@ func CleanupPullNotification(gitea common.Gitea, thread *models.NotificationThre
|
||||
return false // cleaned up now, but the cleanup was not aleady done
|
||||
}
|
||||
|
||||
func SetStatus(gitea common.Gitea, org, repo, hash string, status *models.CommitStatus) error {
|
||||
_, err := gitea.SetCommitStatus(org, repo, hash, status)
|
||||
if err != nil {
|
||||
common.LogError(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) (bool, error) {
|
||||
dir, err := os.MkdirTemp(os.TempDir(), BotName)
|
||||
common.PanicOnError(err)
|
||||
@@ -837,6 +848,22 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) (bool, e
|
||||
TargetURL: ObsWebHost + "/project/show/" + stagingProject,
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
msg := "Unable to setup stage project " + stagingConfig.ObsProject
|
||||
status.Status = common.CommitStatus_Fail
|
||||
common.LogError(msg)
|
||||
if !IsDryRun {
|
||||
SetStatus(gitea, org, repo, pr.Head.Sha, status)
|
||||
_, err = gitea.AddReviewComment(pr, common.ReviewStateRequestChanges, msg)
|
||||
if err != nil {
|
||||
common.LogError(err)
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
msg := "Changed source updated for build"
|
||||
if change == RequestModificationProjectCreated {
|
||||
msg = "Build is started in " + ObsWebHost + "/project/show/" +
|
||||
@@ -845,8 +872,7 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) (bool, e
|
||||
if len(stagingConfig.QA) > 0 {
|
||||
msg = msg + "\nAdditional QA builds: \n"
|
||||
}
|
||||
gitea.SetCommitStatus(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Head.Sha, status)
|
||||
|
||||
SetStatus(gitea, org, repo, pr.Head.Sha, status)
|
||||
for _, setup := range stagingConfig.QA {
|
||||
CreateQASubProject(stagingConfig, git, gitea, pr,
|
||||
stagingProject,
|
||||
@@ -870,32 +896,34 @@ func ProcessPullRequest(gitea common.Gitea, org, repo string, id int64) (bool, e
|
||||
}
|
||||
buildStatus := ProcessBuildStatus(stagingResult, baseResult)
|
||||
|
||||
done := false
|
||||
switch buildStatus {
|
||||
case BuildStatusSummarySuccess:
|
||||
status.Status = common.CommitStatus_Success
|
||||
done = true
|
||||
if !IsDryRun {
|
||||
_, err := gitea.AddReviewComment(pr, common.ReviewStateApproved, "Build successful")
|
||||
if err != nil {
|
||||
common.LogError(err)
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
case BuildStatusSummaryFailed:
|
||||
status.Status = common.CommitStatus_Fail
|
||||
done = true
|
||||
if !IsDryRun {
|
||||
_, err := gitea.AddReviewComment(pr, common.ReviewStateRequestChanges, "Build failed")
|
||||
if err != nil {
|
||||
common.LogError(err)
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
common.LogInfo("Build status:", buildStatus)
|
||||
gitea.SetCommitStatus(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Head.Sha, status)
|
||||
|
||||
// waiting for build results -- nothing to do
|
||||
if !IsDryRun {
|
||||
if err = SetStatus(gitea, org, repo, pr.Head.Sha, status); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return done, nil
|
||||
|
||||
} else if err == NonActionableReviewError || err == NoReviewsFoundError {
|
||||
return true, nil
|
||||
|
@@ -278,12 +278,12 @@ func main() {
|
||||
}
|
||||
|
||||
names := queries["q"]
|
||||
if len(names) < 1 || len(names) > 10 {
|
||||
if len(names) != 1 {
|
||||
res.WriteHeader(400)
|
||||
return
|
||||
}
|
||||
|
||||
packages := FindPackages(names)
|
||||
packages := FindPackages(names[0])
|
||||
data, err := json.MarshalIndent(packages, "", " ")
|
||||
if err != nil {
|
||||
res.WriteHeader(500)
|
||||
@@ -292,6 +292,7 @@ func main() {
|
||||
}
|
||||
|
||||
res.Write(data)
|
||||
res.Header().Add("content-type", "application/json")
|
||||
res.WriteHeader(200)
|
||||
})
|
||||
|
||||
|
@@ -29,13 +29,15 @@ func UpdateResults(r *common.BuildResult) {
|
||||
RepoStatusLock.Lock()
|
||||
defer RepoStatusLock.Unlock()
|
||||
|
||||
updateResultsWithoutLocking(r)
|
||||
}
|
||||
|
||||
func updateResultsWithoutLocking(r *common.BuildResult) {
|
||||
key := "result." + r.Project + "/" + r.Repository + "/" + r.Arch
|
||||
common.LogDebug(" + Updating", key)
|
||||
data, err := redisClient.HGetAll(context.Background(), key).Result()
|
||||
if err != nil {
|
||||
common.LogError("Failed fetching build results for", key, err)
|
||||
}
|
||||
common.LogDebug(" + Update size", len(data))
|
||||
|
||||
reset_time := time.Date(1000, 1, 1, 1, 1, 1, 1, time.Local)
|
||||
for _, pkg := range r.Status {
|
||||
@@ -110,21 +112,15 @@ func FindRepoResults(project, repo string) []*common.BuildResult {
|
||||
return ret
|
||||
}
|
||||
|
||||
func FindPackages(search_terms []string) []string {
|
||||
func FindPackages(pkg string) []string {
|
||||
RepoStatusLock.RLock()
|
||||
defer RepoStatusLock.RUnlock()
|
||||
|
||||
data := make([]string, 0, 100)
|
||||
for _, repo := range RepoStatus {
|
||||
for _, status := range repo.Status {
|
||||
pkg := status.Package
|
||||
match := true
|
||||
for _, term := range search_terms {
|
||||
match = match && strings.Contains(pkg, term)
|
||||
}
|
||||
|
||||
if match {
|
||||
entry := repo.Project + "/" + repo.Status[0].Package
|
||||
if pkg == status.Package {
|
||||
entry := repo.Project + "/" + pkg
|
||||
if idx, found := slices.BinarySearch(data, entry); !found {
|
||||
data = slices.Insert(data, idx, entry)
|
||||
if len(data) >= 100 {
|
||||
@@ -188,6 +184,8 @@ func RescanRepositories() error {
|
||||
RepoStatusLock.Unlock()
|
||||
var count int
|
||||
|
||||
projectsLooked := make([]string, 0, 10000)
|
||||
|
||||
for {
|
||||
var data []string
|
||||
data, cursor, err = redisClient.ScanType(ctx, cursor, "", 1000, "hash").Result()
|
||||
@@ -196,6 +194,7 @@ func RescanRepositories() error {
|
||||
return err
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
RepoStatusLock.Lock()
|
||||
for _, repo := range data {
|
||||
r := strings.Split(repo, "/")
|
||||
@@ -207,14 +206,28 @@ func RescanRepositories() error {
|
||||
Repository: r[1],
|
||||
Arch: r[2],
|
||||
}
|
||||
if pos, found := slices.BinarySearchFunc(RepoStatus, d, common.BuildResultComp); found {
|
||||
|
||||
var pos int
|
||||
var found bool
|
||||
if pos, found = slices.BinarySearchFunc(RepoStatus, d, common.BuildResultComp); found {
|
||||
RepoStatus[pos].Dirty = true
|
||||
} else {
|
||||
d.Dirty = true
|
||||
RepoStatus = slices.Insert(RepoStatus, pos, d)
|
||||
count++
|
||||
}
|
||||
|
||||
// fetch all keys, one per non-maintenance/non-home: projects, for package search
|
||||
if idx, found := slices.BinarySearch(projectsLooked, d.Project); !found && !strings.Contains(d.Project, ":Maintenance:") && (len(d.Project) < 5 || d.Project[0:5] != "home:") {
|
||||
projectsLooked = slices.Insert(projectsLooked, idx, d.Project)
|
||||
wg.Add(1)
|
||||
go func(r *common.BuildResult) {
|
||||
updateResultsWithoutLocking(r)
|
||||
wg.Done()
|
||||
}(RepoStatus[pos])
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
RepoStatusLock.Unlock()
|
||||
|
||||
if cursor == 0 {
|
||||
|
Reference in New Issue
Block a user