mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package convert
|
|
|
|
import (
|
|
"testing"
|
|
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
"github.com/hanzoai/git/models/perm"
|
|
access_model "github.com/hanzoai/git/models/perm/access"
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
"github.com/hanzoai/git/models/unittest"
|
|
"github.com/hanzoai/git/modules/structs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPullRequest_APIFormat(t *testing.T) {
|
|
// with HeadRepo
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
|
assert.NoError(t, pr.LoadAttributes(t.Context()))
|
|
assert.NoError(t, pr.LoadIssue(t.Context()))
|
|
apiPullRequest := ToAPIPullRequest(t.Context(), pr, nil)
|
|
assert.NotNil(t, apiPullRequest)
|
|
assert.Equal(t, &structs.PRBranchInfo{
|
|
Name: "branch1",
|
|
Ref: "refs/pull/2/head",
|
|
Sha: "4a357436d925b5c974181ff12a994538ddc5a269",
|
|
RepoID: 1,
|
|
Repository: ToRepo(t.Context(), headRepo, access_model.Permission{AccessMode: perm.AccessModeRead}),
|
|
}, apiPullRequest.Head)
|
|
|
|
// withOut HeadRepo
|
|
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
|
assert.NoError(t, pr.LoadIssue(t.Context()))
|
|
assert.NoError(t, pr.LoadAttributes(t.Context()))
|
|
// simulate fork deletion
|
|
pr.HeadRepo = nil
|
|
pr.HeadRepoID = 100000
|
|
apiPullRequest = ToAPIPullRequest(t.Context(), pr, nil)
|
|
assert.NotNil(t, apiPullRequest)
|
|
assert.Nil(t, apiPullRequest.Head.Repository)
|
|
assert.EqualValues(t, -1, apiPullRequest.Head.RepoID)
|
|
|
|
apiPullRequests, err := ToAPIPullRequests(t.Context(), pr.BaseRepo, []*issues_model.PullRequest{pr}, nil)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, apiPullRequests, 1)
|
|
assert.NotNil(t, apiPullRequests[0])
|
|
assert.Nil(t, apiPullRequests[0].Head.Repository)
|
|
assert.EqualValues(t, -1, apiPullRequests[0].Head.RepoID)
|
|
}
|