From 76f2ae8aec0f22b28d08d17243974e90a8754bed48c85a3bc8d65cc7c2acbaaa Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 27 Sep 2024 17:55:49 +0200 Subject: [PATCH] common: find pull requests by source and target --- bots-common/gitea_utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bots-common/gitea_utils.go b/bots-common/gitea_utils.go index 40ff94d..e4c937f 100644 --- a/bots-common/gitea_utils.go +++ b/bots-common/gitea_utils.go @@ -240,7 +240,7 @@ func (gitea *GiteaTransport) CreateRepositoryIfNotExist(git *GitHandler, org Org 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{ Base: repo.DefaultBranch, Head: srcId, @@ -248,6 +248,13 @@ func (gitea *GiteaTransport) CreatePullRequest(repo *models.Repository, srcId, t 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( repository. NewRepoCreatePullRequestParams(). @@ -485,4 +492,3 @@ func (gitea *GiteaTransport) GetRecentCommits(org, repo, branch string, commitNo return commits.Payload, nil } -