.
This commit is contained in:
@@ -45,6 +45,16 @@ func fetchPrGit(h *common.RequestHandler, pr *models.PullRequest) error {
|
||||
return h.Error
|
||||
}
|
||||
|
||||
func getObsProjectAssociatedWithPr(baseProject string, pr *models.PullRequest) string {
|
||||
return fmt.Sprintf(
|
||||
"%s:%s:%s:PR:%d",
|
||||
baseProject,
|
||||
common.ObsSafeProjectName(pr.Base.Repo.Owner.UserName),
|
||||
common.ObsSafeProjectName(pr.Base.Repo.Name),
|
||||
pr.Index,
|
||||
)
|
||||
}
|
||||
|
||||
func processPullNotification(h *common.RequestHandler, notification *models.NotificationSubject) {
|
||||
rx := regexp.MustCompile(`^https://src\.(?:open)?suse\.(?:org|de)/api/v\d+/repos/(?<org>[a-zA-Z0-9]+)/(?<project>[_a-zA-Z0-9]+)/issues/(?<num>[0-9]+)$`)
|
||||
match := rx.FindStringSubmatch(notification.URL)
|
||||
@@ -104,38 +114,40 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
||||
continue
|
||||
}
|
||||
|
||||
err := fetchPrGit(h, pr)
|
||||
if err != nil {
|
||||
h.LogError("Cannot fetch PR git: %s", pr.URL)
|
||||
return
|
||||
}
|
||||
|
||||
dir := pr.Head.Sha
|
||||
headSubmodules := h.GitSubmoduleList(dir, pr.Head.Sha)
|
||||
baseSubmodules := h.GitSubmoduleList(dir, pr.Base.Sha)
|
||||
|
||||
modifiedOrNew := make([]string, 0, 16)
|
||||
for pkg, headOid := range headSubmodules {
|
||||
if baseOid, exists := baseSubmodules[pkg]; !exists || baseOid != headOid {
|
||||
modifiedOrNew = append(modifiedOrNew, pkg)
|
||||
}
|
||||
}
|
||||
|
||||
// find modified submodules and new submodules -- build them
|
||||
|
||||
h.Log("processing state...")
|
||||
|
||||
switch review.State {
|
||||
// create build project, if doesn't exist, and add it to pending requests
|
||||
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
||||
h.Log("repo content fetching ...")
|
||||
buildPrjBytes, err := h.GetPullRequestFileContent(pr, "project.build")
|
||||
err := fetchPrGit(h, pr)
|
||||
if err != nil {
|
||||
h.LogPlainError(err)
|
||||
h.LogError("Cannot fetch PR git: %s", pr.URL)
|
||||
return
|
||||
}
|
||||
|
||||
// find modified submodules and new submodules -- build them
|
||||
dir := pr.Head.Sha
|
||||
headSubmodules := h.GitSubmoduleList(dir, pr.Head.Sha)
|
||||
baseSubmodules := h.GitSubmoduleList(dir, pr.Base.Sha)
|
||||
|
||||
modifiedOrNew := make([]string, 0, 16)
|
||||
for pkg, headOid := range headSubmodules {
|
||||
if baseOid, exists := baseSubmodules[pkg]; !exists || baseOid != headOid {
|
||||
modifiedOrNew = append(modifiedOrNew, pkg)
|
||||
}
|
||||
}
|
||||
|
||||
h.Log("repo content fetching ...")
|
||||
buildPrjBytes := h.GitCatFile(dir, pr.Head.Sha, "project.build")
|
||||
// buildPrjBytes, err := h.GetPullRequestFileContent(pr, "project.build")
|
||||
if h.HasError() {
|
||||
h.LogPlainError(h.Error)
|
||||
/*
|
||||
_, err := h.AddReviewComment(pr, common.ReviewStateRequestChanges, "Cannot find reference project")
|
||||
if err != nil {
|
||||
h.LogPlainError(err)
|
||||
}
|
||||
*/
|
||||
return
|
||||
}
|
||||
|
||||
@@ -150,12 +162,7 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
||||
// disable publishing
|
||||
|
||||
// TODO: escape things here
|
||||
meta.Name = fmt.Sprintf("%s:%s:%s:PR:%d",
|
||||
obsClient.HomeProject,
|
||||
common.ObsSafeProjectName(pr.Base.Repo.Owner.UserName),
|
||||
common.ObsSafeProjectName(pr.Base.Repo.Name),
|
||||
pr.Index,
|
||||
)
|
||||
meta.Name = getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
||||
meta.Description = fmt.Sprintf(`Pull request build job: %s%s PR#%d`,
|
||||
"https://src.opensuse.org", pr.Base.Repo.Name, pr.Index)
|
||||
urlPkg := make([]string, 0, len(modifiedOrNew))
|
||||
@@ -185,12 +192,14 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
||||
// set the review state to pending
|
||||
|
||||
case common.ReviewStatePending:
|
||||
// waiting for build results
|
||||
// waiting for build results
|
||||
// project := getObsProjectAssociatedWithPr(obsClient.HomeProject, pr)
|
||||
case common.ReviewStateApproved:
|
||||
// done, mark notification as read
|
||||
// done, mark notification as read
|
||||
h.Log("processing request for success build ...")
|
||||
case common.ReviewStateRequestChanges:
|
||||
h.Log("processing request for failed request changes...")
|
||||
// build failures, nothing to do here, mark notification as read
|
||||
h.Log("processing request for failed request changes...")
|
||||
}
|
||||
|
||||
break
|
||||
|
Reference in New Issue
Block a user