mirror of https://github.com/go-gitea/gitea.git
improvements
parent
c33886fd7a
commit
1cf2e663ae
|
|
@ -216,7 +216,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||||
}
|
}
|
||||||
|
|
||||||
pr.HeadCommitID = opts.NewCommitIDs[i]
|
pr.HeadCommitID = opts.NewCommitIDs[i]
|
||||||
if err = pull_service.UpdatePullRequestAgitFlowHead(ctx, pr, pr.HeadCommitID); err != nil {
|
if err = pull_service.UpdatePullRequestHeadRef(ctx, pr); err != nil {
|
||||||
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
|
return nil, fmt.Errorf("failed to update pull ref. Error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,12 +123,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
|
||||||
issue.PullRequest = pr
|
issue.PullRequest = pr
|
||||||
|
|
||||||
// update head commit id into git repository
|
// update head commit id into git repository
|
||||||
if pr.Flow == issues_model.PullRequestFlowAGit {
|
if err = UpdatePullRequestHeadRef(ctx, pr); err != nil {
|
||||||
err = UpdatePullRequestAgitFlowHead(ctx, pr, pr.HeadCommitID)
|
|
||||||
} else {
|
|
||||||
err = UpdatePullRequestGithubFlowHead(ctx, pr)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,7 +383,7 @@ func AddTestPullRequestTask(opts TestPullRequestOptions) {
|
||||||
log.Trace("Updating PR[%d]: composing new test task", pr.ID)
|
log.Trace("Updating PR[%d]: composing new test task", pr.ID)
|
||||||
pr.HeadRepo = repo // avoid loading again
|
pr.HeadRepo = repo // avoid loading again
|
||||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||||
if err := UpdatePullRequestGithubFlowHead(ctx, pr); err != nil {
|
if err := UpdatePullRequestHeadRef(ctx, pr); err != nil {
|
||||||
log.Error("PushToBaseRepo: %v", err)
|
log.Error("PushToBaseRepo: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -549,7 +544,7 @@ func UpdatePullsRefs(ctx context.Context, repo *repo_model.Repository, update *r
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
log.Trace("Updating PR[%d]: composing new test task", pr.ID)
|
log.Trace("Updating PR[%d]: composing new test task", pr.ID)
|
||||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||||
if err := UpdatePullRequestGithubFlowHead(ctx, pr); err != nil {
|
if err := UpdatePullRequestHeadRef(ctx, pr); err != nil {
|
||||||
log.Error("UpdatePullRequestHead: %v", err)
|
log.Error("UpdatePullRequestHead: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -557,31 +552,30 @@ func UpdatePullsRefs(ctx context.Context, repo *repo_model.Repository, update *r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdatePullRequestAgitFlowHead(ctx context.Context, pr *issues_model.PullRequest, commitID string) error {
|
|
||||||
log.Trace("UpdateAgitPullRequestHead[%d]: update pull request head in base repo '%s'", pr.ID, pr.GetGitHeadRefName())
|
|
||||||
|
|
||||||
return gitrepo.UpdateRef(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), commitID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatePullRequestHeadRef updates the head reference of a pull request
|
// UpdatePullRequestHeadRef updates the head reference of a pull request
|
||||||
func UpdatePullRequestGithubFlowHead(ctx context.Context, pr *issues_model.PullRequest) error {
|
func UpdatePullRequestHeadRef(ctx context.Context, pr *issues_model.PullRequest) error {
|
||||||
log.Trace("UpdatePullRequestHeadRef[%d]: update pull request ref in base repo '%s'", pr.ID, pr.GetGitHeadRefName())
|
log.Trace("UpdatePullRequestHeadRef[%d]: update pull request ref in base repo '%s'", pr.ID, pr.GetGitHeadRefName())
|
||||||
|
|
||||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pr.Flow == issues_model.PullRequestFlowAGit {
|
||||||
|
if pr.HeadCommitID == "" {
|
||||||
|
return errors.New("head commit ID cannot be empty for agit flow")
|
||||||
|
}
|
||||||
|
return gitrepo.UpdateRef(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), pr.HeadCommitID)
|
||||||
|
}
|
||||||
|
|
||||||
if !pr.IsSameRepo() { // for cross repository pull request
|
if !pr.IsSameRepo() { // for cross repository pull request
|
||||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitrepo.FetchRemoteBranch(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), pr.HeadRepo, pr.HeadBranch); err != nil {
|
return gitrepo.FetchRemoteBranch(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), pr.HeadRepo, pr.HeadBranch)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return gitrepo.UpdateRef(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), pr.HeadCommitID)
|
return gitrepo.UpdateRef(ctx, pr.BaseRepo, pr.GetGitHeadRefName(), pr.HeadBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// retargetBranchPulls change target branch for all pull requests whose base branch is the branch
|
// retargetBranchPulls change target branch for all pull requests whose base branch is the branch
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue