Merge remote-tracking branch 'gitea/main'
This commit is contained in:
@@ -34,6 +34,7 @@ import (
|
|||||||
apiclient "src.opensuse.org/autogits/common/gitea-generated/client"
|
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/notification"
|
||||||
"src.opensuse.org/autogits/common/gitea-generated/client/organization"
|
"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/repository"
|
||||||
"src.opensuse.org/autogits/common/gitea-generated/client/user"
|
"src.opensuse.org/autogits/common/gitea-generated/client/user"
|
||||||
"src.opensuse.org/autogits/common/gitea-generated/models"
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||||
@@ -63,6 +64,10 @@ const (
|
|||||||
ReviewStateUnknown models.ReviewStateType = ""
|
ReviewStateUnknown models.ReviewStateType = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type GiteaComment interface {
|
||||||
|
AddComment(pr *models.PullRequest, comment string) (error)
|
||||||
|
}
|
||||||
|
|
||||||
type GiteaMaintainershipReader interface {
|
type GiteaMaintainershipReader interface {
|
||||||
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, string, error)
|
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, string, error)
|
||||||
FetchMaintainershipDirFile(org, prjGit, branch, pkg string) ([]byte, string, error)
|
FetchMaintainershipDirFile(org, prjGit, branch, pkg string) ([]byte, string, error)
|
||||||
@@ -100,6 +105,7 @@ type GiteaRepoFetcher interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Gitea interface {
|
type Gitea interface {
|
||||||
|
GiteaComment
|
||||||
GiteaRepoFetcher
|
GiteaRepoFetcher
|
||||||
GiteaReviewRequester
|
GiteaReviewRequester
|
||||||
GiteaReviewer
|
GiteaReviewer
|
||||||
@@ -459,8 +465,15 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
|
|||||||
transport.DefaultAuthentication,
|
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().
|
issue.NewIssueCreateCommentParams().
|
||||||
WithDefaults().
|
WithDefaults().
|
||||||
WithOwner(pr.Base.Repo.Owner.UserName).
|
WithOwner(pr.Base.Repo.Owner.UserName).
|
||||||
@@ -469,13 +482,13 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
|
|||||||
WithBody(&models.CreateIssueCommentOption{
|
WithBody(&models.CreateIssueCommentOption{
|
||||||
Body: &comment,
|
Body: &comment,
|
||||||
}),
|
}),
|
||||||
transport.DefaultAuthentication)
|
gitea.transport.DefaultAuthentication)
|
||||||
*/
|
|
||||||
if err != nil {
|
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) {
|
func (gitea *GiteaTransport) GetRepositoryFileContent(org, repo, hash, path string) ([]byte, string, error) {
|
||||||
|
|||||||
@@ -641,6 +641,11 @@ var ObsRepoStatusDetails map[string]ObsBuildStatusDetail = map[string]ObsBuildSt
|
|||||||
Description: "The repository state is being calculated right now",
|
Description: "The repository state is being calculated right now",
|
||||||
Finished: false,
|
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) {
|
func parseBuildResults(data []byte) (*BuildResultList, error) {
|
||||||
|
|||||||
@@ -93,6 +93,14 @@ func getObsProjectAssociatedWithPr(baseProject string, pr *models.PullRequest) s
|
|||||||
func processBuildStatusUpdate() {
|
func processBuildStatusUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestModification int
|
||||||
|
|
||||||
|
const (
|
||||||
|
RequestModificationNoChange = 1
|
||||||
|
RequestModificationProjectCreated = 2
|
||||||
|
RequestModificationSourceChanged = 3
|
||||||
|
)
|
||||||
|
|
||||||
type BuildStatusSummary int
|
type BuildStatusSummary int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -317,13 +325,13 @@ func generateObsPrjMeta(git common.Git, gitea common.Gitea, pr *models.PullReque
|
|||||||
return meta, nil
|
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")
|
log.Println("fetching OBS project Meta")
|
||||||
obsPrProject := getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
obsPrProject := getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
||||||
meta, err := obsClient.GetProjectMeta(obsPrProject)
|
meta, err := obsClient.GetProjectMeta(obsPrProject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error fetching project meta for", obsPrProject, ":", err)
|
log.Println("error fetching project meta for", obsPrProject, ":", err)
|
||||||
return err
|
return RequestModificationNoChange, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta != nil {
|
if meta != nil {
|
||||||
@@ -334,28 +342,31 @@ func startOrUpdateBuild(git common.Git, gitea common.Gitea, pr *models.PullReque
|
|||||||
} else {
|
} else {
|
||||||
if path.Fragment == pr.Head.Sha {
|
if path.Fragment == pr.Head.Sha {
|
||||||
// build in progress
|
// build in progress
|
||||||
return nil
|
return RequestModificationNoChange, nil
|
||||||
}
|
}
|
||||||
// build needs update
|
// build needs update
|
||||||
log.Println("Detected Head update... regenerating build...")
|
log.Println("Detected Head update... regenerating build...")
|
||||||
meta = nil
|
meta = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var state RequestModification
|
||||||
|
state = RequestModificationSourceChanged
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
// new build
|
// new build
|
||||||
meta, err = generateObsPrjMeta(git, gitea, pr, obsClient)
|
meta, err = generateObsPrjMeta(git, gitea, pr, obsClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return RequestModificationNoChange, err
|
||||||
}
|
}
|
||||||
|
state = RequestModificationProjectCreated
|
||||||
}
|
}
|
||||||
|
|
||||||
err = obsClient.SetProjectMeta(meta)
|
err = obsClient.SetProjectMeta(meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("cannot create meta project:", err)
|
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) {
|
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...")
|
||||||
|
log.Println("processing state... %d", review.State)
|
||||||
|
|
||||||
|
|
||||||
switch review.State {
|
switch review.State {
|
||||||
|
|
||||||
// create build project, if doesn't exist, and add it to pending requests
|
// create build project, if doesn't exist, and add it to pending requests
|
||||||
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
case common.ReviewStateUnknown:
|
||||||
if err := startOrUpdateBuild(git, gitea, pr, obsClient); err != nil {
|
// what to do?
|
||||||
|
|
||||||
|
|
||||||
|
case common.ReviewStatePending, common.ReviewStateRequestReview:
|
||||||
|
change, err := startOrUpdateBuild(git, gitea, pr, obsClient)
|
||||||
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if change != RequestModificationNoChange {
|
||||||
msg := "Build is started in https://" + obsWebHost + "/project/show/" +
|
msg := "Changed source updated for build"
|
||||||
|
if change == RequestModificationProjectCreated {
|
||||||
|
msg = "Build is started in https://" + obsWebHost + "/project/show/" +
|
||||||
getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
||||||
gitea.AddReviewComment(pr, common.ReviewStatePending, msg)
|
}
|
||||||
|
gitea.AddComment(pr, 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 {
|
if err != nil {
|
||||||
log.Println("Cannot fetch PR git:", pr.URL)
|
log.Println("Cannot fetch PR git:", pr.URL)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user