common: find pull requests by source and target

This commit is contained in:
Adam Majer 2024-09-27 17:55:49 +02:00
parent a0b65ea8f4
commit 76f2ae8aec

View File

@ -240,7 +240,7 @@ func (gitea *GiteaTransport) CreateRepositoryIfNotExist(git *GitHandler, org Org
return repo.Payload, nil return repo.Payload, nil
} }
func (gitea *GiteaTransport) CreatePullRequest(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error) { func (gitea *GiteaTransport) CreatePullRequestIfNotExist(repo *models.Repository, srcId, targetId, title, body string) (*models.PullRequest, error) {
prOptions := models.CreatePullRequestOption{ prOptions := models.CreatePullRequestOption{
Base: repo.DefaultBranch, Base: repo.DefaultBranch,
Head: srcId, Head: srcId,
@ -248,6 +248,13 @@ func (gitea *GiteaTransport) CreatePullRequest(repo *models.Repository, srcId, t
Body: body, Body: body,
} }
if pr, err := gitea.client.Repository.RepoGetPullRequestByBaseHead(
repository.NewRepoGetPullRequestByBaseHeadParams().WithOwner(repo.Owner.UserName).WithRepo(repo.Name).WithBase(repo.DefaultBranch).WithHead(srcId),
gitea.transport.DefaultAuthentication,
); err == nil {
return pr.Payload, nil
}
pr, err := gitea.client.Repository.RepoCreatePullRequest( pr, err := gitea.client.Repository.RepoCreatePullRequest(
repository. repository.
NewRepoCreatePullRequestParams(). NewRepoCreatePullRequestParams().
@ -485,4 +492,3 @@ func (gitea *GiteaTransport) GetRecentCommits(org, repo, branch string, commitNo
return commits.Payload, nil return commits.Payload, nil
} }