fix: return API URL in the url field for pull requests using the API (#12643)
closes #10451 ### Tests for Go changes - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I ran... - [ ] `make pr-go` before pushing ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/12643): <!--number 12643 --><!--line 0 --><!--description cmV0dXJuIEFQSSBVUkwgaW4gdGhlIGB1cmxgIGZpZWxkIGZvciBwdWxsIHJlcXVlc3RzIHVzaW5nIHRoZSBBUEk=-->return API URL in the `url` field for pull requests using the API<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12643 Reviewed-by: Robert Wolff <mahlzahn@posteo.de> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
This commit is contained in:
@@ -386,7 +386,14 @@ func (issue *Issue) APIURL(ctx context.Context) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/issues/%d", issue.Repo.APIURL(), issue.Index)
|
||||
|
||||
var path string
|
||||
if issue.IsPull {
|
||||
path = "pulls"
|
||||
} else {
|
||||
path = "issues"
|
||||
}
|
||||
return fmt.Sprintf("%s/%s/%d", issue.Repo.APIURL(), path, issue.Index)
|
||||
}
|
||||
|
||||
// HTMLURL returns the absolute URL to this issue.
|
||||
|
||||
@@ -67,6 +67,10 @@ func TestIssueAPIURL(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL(db.DefaultContext))
|
||||
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
||||
require.NoError(t, pr.LoadIssue(db.DefaultContext))
|
||||
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/pulls/2", pr.Issue.APIURL(db.DefaultContext))
|
||||
}
|
||||
|
||||
func TestGetIssuesByIDs(t *testing.T) {
|
||||
|
||||
@@ -67,7 +67,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||
|
||||
apiPullRequest := &api.PullRequest{
|
||||
ID: pr.ID,
|
||||
URL: pr.Issue.HTMLURL(),
|
||||
URL: pr.Issue.APIURL(ctx),
|
||||
Index: pr.Index,
|
||||
Poster: apiIssue.Poster,
|
||||
Title: apiIssue.Title,
|
||||
|
||||
@@ -534,7 +534,7 @@ func TestActionsPullRequestTrustCancelOnClose(t *testing.T) {
|
||||
|
||||
regularUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
||||
regularSession := loginUser(t, regularUser.Name)
|
||||
token := getTokenForLoggedInUser(t, regularSession, auth_model.AccessTokenScopeWriteIssue)
|
||||
token := getTokenForLoggedInUser(t, regularSession, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
baseRepo, f := actionsTrustTestCreateBaseRepo(t, ownerUser)
|
||||
defer f()
|
||||
|
||||
@@ -299,6 +299,7 @@ func TestAPICreatePullSuccess(t *testing.T) {
|
||||
DecodeJSON(t, res, pull)
|
||||
|
||||
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", pull.MergeBase)
|
||||
assert.Contains(t, pull.URL, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner10.Name, repo10.Name, pull.Index))
|
||||
}
|
||||
|
||||
func TestAPICreatePullSameRepoSuccess(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user