Merge remote-tracking branch 'gitea/main'

This commit is contained in:
2025-04-04 13:06:28 +02:00
3 changed files with 58 additions and 23 deletions

View File

@@ -34,6 +34,7 @@ import (
apiclient "src.opensuse.org/autogits/common/gitea-generated/client"
"src.opensuse.org/autogits/common/gitea-generated/client/notification"
"src.opensuse.org/autogits/common/gitea-generated/client/organization"
"src.opensuse.org/autogits/common/gitea-generated/client/issue"
"src.opensuse.org/autogits/common/gitea-generated/client/repository"
"src.opensuse.org/autogits/common/gitea-generated/client/user"
"src.opensuse.org/autogits/common/gitea-generated/models"
@@ -63,6 +64,10 @@ const (
ReviewStateUnknown models.ReviewStateType = ""
)
type GiteaComment interface {
AddComment(pr *models.PullRequest, comment string) (error)
}
type GiteaMaintainershipReader interface {
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, string, error)
FetchMaintainershipDirFile(org, prjGit, branch, pkg string) ([]byte, string, error)
@@ -100,6 +105,7 @@ type GiteaRepoFetcher interface {
}
type Gitea interface {
GiteaComment
GiteaRepoFetcher
GiteaReviewRequester
GiteaReviewer
@@ -459,8 +465,15 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
transport.DefaultAuthentication,
)
*/
if err != nil {
return nil, err
}
/* c, err := client.Issue.IssueCreateComment(
return c.Payload, nil
}
func (gitea *GiteaTransport) AddComment(pr *models.PullRequest, comment string) (error) {
_, err := gitea.client.Issue.IssueCreateComment(
issue.NewIssueCreateCommentParams().
WithDefaults().
WithOwner(pr.Base.Repo.Owner.UserName).
@@ -469,13 +482,13 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
WithBody(&models.CreateIssueCommentOption{
Body: &comment,
}),
transport.DefaultAuthentication)
*/
gitea.transport.DefaultAuthentication)
if err != nil {
return nil, err
return err
}
return c.Payload, nil
return nil
}
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error) {

View File

@@ -641,6 +641,11 @@ var ObsRepoStatusDetails map[string]ObsBuildStatusDetail = map[string]ObsBuildSt
Description: "The repository state is being calculated right now",
Finished: false,
},
"unknown": ObsBuildStatusDetail{
Code: "unknown",
Description: "The repository state has not been seen by the scheduler yet",
Finished: false,
},
}
func parseBuildResults(data []byte) (*BuildResultList, error) {

View File

@@ -93,6 +93,14 @@ func getObsProjectAssociatedWithPr(baseProject string, pr *models.PullRequest) s
func processBuildStatusUpdate() {
}
type RequestModification int
const (
RequestModificationNoChange = 1
RequestModificationProjectCreated = 2
RequestModificationSourceChanged = 3
)
type BuildStatusSummary int
const (
@@ -317,13 +325,13 @@ func generateObsPrjMeta(git common.Git, gitea common.Gitea, pr *models.PullReque
return meta, nil
}
func startOrUpdateBuild(git common.Git, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) error {
func startOrUpdateBuild(git common.Git, gitea common.Gitea, pr *models.PullRequest, obsClient *common.ObsClient) (RequestModification, error) {
log.Println("fetching OBS project Meta")
obsPrProject := getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
meta, err := obsClient.GetProjectMeta(obsPrProject)
if err != nil {
log.Println("error fetching project meta for", obsPrProject, ":", err)
return err
return RequestModificationNoChange, err
}
if meta != nil {
@@ -334,28 +342,31 @@ func startOrUpdateBuild(git common.Git, gitea common.Gitea, pr *models.PullReque
} else {
if path.Fragment == pr.Head.Sha {
// build in progress
return nil
return RequestModificationNoChange, nil
}
// build needs update
log.Println("Detected Head update... regenerating build...")
meta = nil
}
}
var state RequestModification
state = RequestModificationSourceChanged
if meta == nil {
// new build
meta, err = generateObsPrjMeta(git, gitea, pr, obsClient)
if err != nil {
return err
return RequestModificationNoChange, err
}
state = RequestModificationProjectCreated
}
err = obsClient.SetProjectMeta(meta)
if err != nil {
log.Println("cannot create meta project:", err)
return err
return RequestModificationNoChange, err
}
return nil
return state, nil
}
func processPullNotification(gitea common.Gitea, thread *models.NotificationThread) {
@@ -454,25 +465,31 @@ func processPullNotification(gitea common.Gitea, thread *models.NotificationThre
}
log.Println("processing state...")
log.Println("processing state... %d", review.State)
switch review.State {
// create build project, if doesn't exist, and add it to pending requests
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
if err := startOrUpdateBuild(git, gitea, pr, obsClient); err != nil {
case common.ReviewStateUnknown:
// what to do?
case common.ReviewStatePending, common.ReviewStateRequestReview:
change, err := startOrUpdateBuild(git, gitea, pr, obsClient)
if err != nil {
return
}
if change != RequestModificationNoChange {
msg := "Changed source updated for build"
if change == RequestModificationProjectCreated {
msg = "Build is started in https://" + obsWebHost + "/project/show/" +
getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
}
gitea.AddComment(pr, msg)
}
msg := "Build is started in https://" + obsWebHost + "/project/show/" +
getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
gitea.AddReviewComment(pr, common.ReviewStatePending, msg)
case common.ReviewStatePending:
if err := startOrUpdateBuild(git, gitea, pr, obsClient); err != nil {
return
}
err := fetchPrGit(git, pr)
err = fetchPrGit(git, pr)
if err != nil {
log.Println("Cannot fetch PR git:", pr.URL)
return