This commit is contained in:
Adam Majer 2024-07-10 11:41:34 +02:00
parent 262cc0ff91
commit fe58462b59
2 changed files with 19 additions and 8 deletions

View File

@ -91,7 +91,7 @@ func (h *RequestHandler) CreateRepositoryIfNotExist(org Organization, repoName s
return repo.Payload return repo.Payload
} }
func (h *RequestHandler) CreatePullRequest(repo *models.Repository, srcId, targetId string) *models.PullRequest { func (h *RequestHandler) CreatePullRequest(repo *models.Repository, srcId, targetId, title, body string) *models.PullRequest {
if h.HasError() { if h.HasError() {
return nil return nil
} }
@ -99,9 +99,12 @@ func (h *RequestHandler) CreatePullRequest(repo *models.Repository, srcId, targe
transport := h.allocateGiteaTransport() transport := h.allocateGiteaTransport()
client := apiclient.New(transport, nil) client := apiclient.New(transport, nil)
var prOptions models.CreatePullRequestOption prOptions := models.CreatePullRequestOption{
prOptions.Base = repo.DefaultBranch Base: repo.DefaultBranch,
prOptions.Head = srcId Head: srcId,
Title: title,
Body: body,
}
pr, err := client.Repository.RepoCreatePullRequest( pr, err := client.Repository.RepoCreatePullRequest(
repository. repository.
@ -136,8 +139,9 @@ func (h *RequestHandler) RequestReviews(pr *models.PullRequest, reviewer string)
transport := h.allocateGiteaTransport() transport := h.allocateGiteaTransport()
client := apiclient.New(transport, nil) client := apiclient.New(transport, nil)
var reviewOptions models.PullReviewRequestOptions reviewOptions := models.PullReviewRequestOptions{
reviewOptions.Reviewers = []string{reviewer} Reviewers: []string{reviewer},
}
review, err := client.Repository.RepoCreatePullReviewRequests( review, err := client.Repository.RepoCreatePullReviewRequests(
repository. repository.

View File

@ -12,7 +12,6 @@ const (
GitAuthor = "GiteaBot - AutoStaging" GitAuthor = "GiteaBot - AutoStaging"
PrReview = "pr-review" PrReview = "pr-review"
) )
func processPullRequestOpened(h *common.RequestHandler) error { func processPullRequestOpened(h *common.RequestHandler) error {
@ -45,7 +44,15 @@ PullRequest: %s#%d`, req.Repository.Name, GitAuthor, req.Repository.Name, req.Pu
h.GitExec(common.DefaultGitPrj, "commit", "-a", "-m", commitMsg) h.GitExec(common.DefaultGitPrj, "commit", "-a", "-m", commitMsg)
h.GitExec(common.DefaultGitPrj, "push", "-f", "origin", branchName) h.GitExec(common.DefaultGitPrj, "push", "-f", "origin", branchName)
PR := h.CreatePullRequest(prjGit, branchName, prjGit.DefaultBranch) PR := h.CreatePullRequest(prjGit, branchName, prjGit.DefaultBranch,
fmt.Sprintf("Forwarded PR: %s", req.Repository.Name),
fmt.Sprintf(`This is a forwarded pull request by %s
referencing the following pull request:
PullRequest: %s#%d
`, GitAuthor, req.Repository.Name, req.Pull_Request.Number),
)
if h.HasError() { if h.HasError() {
return h.Error return h.Error
} }