You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
431 lines
12 KiB
431 lines
12 KiB
6 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
|
// Copyright 2018 Jonas Franz. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package migrations
|
||
|
|
||
|
import (
|
||
4 years ago
|
"context"
|
||
5 years ago
|
"os"
|
||
6 years ago
|
"testing"
|
||
|
"time"
|
||
|
|
||
3 years ago
|
base "code.gitea.io/gitea/modules/migration"
|
||
6 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestGitHubDownloadRepo(t *testing.T) {
|
||
5 years ago
|
GithubLimitRateRemaining = 3 //Wait at 3 remaining since we could have 3 CI in //
|
||
4 years ago
|
downloader := NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", os.Getenv("GITHUB_READ_TOKEN"), "go-gitea", "test_repo")
|
||
5 years ago
|
err := downloader.RefreshRate()
|
||
|
assert.NoError(t, err)
|
||
|
|
||
6 years ago
|
repo, err := downloader.GetRepoInfo()
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assertRepositoryEqual(t, &base.Repository{
|
||
4 years ago
|
Name: "test_repo",
|
||
|
Owner: "go-gitea",
|
||
|
Description: "Test repository for testing migration from github to gitea",
|
||
|
CloneURL: "https://github.com/go-gitea/test_repo.git",
|
||
|
OriginalURL: "https://github.com/go-gitea/test_repo",
|
||
|
DefaultBranch: "master",
|
||
6 years ago
|
}, repo)
|
||
|
|
||
5 years ago
|
topics, err := downloader.GetTopics()
|
||
|
assert.NoError(t, err)
|
||
|
assert.Contains(t, topics, "gitea")
|
||
|
|
||
6 years ago
|
milestones, err := downloader.GetMilestones()
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assertMilestonesEqual(t, []*base.Milestone{
|
||
|
{
|
||
|
Title: "1.0.0",
|
||
|
Description: "Milestone 1.0.0",
|
||
|
Deadline: timePtr(time.Date(2019, 11, 11, 8, 0, 0, 0, time.UTC)),
|
||
|
Created: time.Date(2019, 11, 12, 19, 37, 8, 0, time.UTC),
|
||
|
Updated: timePtr(time.Date(2019, 11, 12, 21, 56, 17, 0, time.UTC)),
|
||
|
Closed: timePtr(time.Date(2019, 11, 12, 19, 45, 49, 0, time.UTC)),
|
||
|
State: "closed",
|
||
|
},
|
||
|
{
|
||
|
Title: "1.1.0",
|
||
|
Description: "Milestone 1.1.0",
|
||
|
Deadline: timePtr(time.Date(2019, 11, 12, 8, 0, 0, 0, time.UTC)),
|
||
|
Created: time.Date(2019, 11, 12, 19, 37, 25, 0, time.UTC),
|
||
|
Updated: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)),
|
||
|
Closed: timePtr(time.Date(2019, 11, 12, 19, 45, 46, 0, time.UTC)),
|
||
|
State: "closed",
|
||
|
},
|
||
|
}, milestones)
|
||
6 years ago
|
|
||
|
labels, err := downloader.GetLabels()
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assertLabelsEqual(t, []*base.Label{
|
||
|
{
|
||
|
Name: "bug",
|
||
|
Color: "d73a4a",
|
||
|
Description: "Something isn't working",
|
||
|
},
|
||
|
{
|
||
|
Name: "documentation",
|
||
|
Color: "0075ca",
|
||
|
Description: "Improvements or additions to documentation",
|
||
|
},
|
||
|
{
|
||
|
Name: "duplicate",
|
||
|
Color: "cfd3d7",
|
||
|
Description: "This issue or pull request already exists",
|
||
|
},
|
||
|
{
|
||
|
Name: "enhancement",
|
||
|
Color: "a2eeef",
|
||
|
Description: "New feature or request",
|
||
|
},
|
||
|
{
|
||
|
Name: "good first issue",
|
||
|
Color: "7057ff",
|
||
|
Description: "Good for newcomers",
|
||
|
},
|
||
|
{
|
||
|
Name: "help wanted",
|
||
|
Color: "008672",
|
||
|
Description: "Extra attention is needed",
|
||
|
},
|
||
|
{
|
||
|
Name: "invalid",
|
||
|
Color: "e4e669",
|
||
|
Description: "This doesn't seem right",
|
||
|
},
|
||
|
{
|
||
|
Name: "question",
|
||
|
Color: "d876e3",
|
||
|
Description: "Further information is requested",
|
||
|
},
|
||
|
{
|
||
|
Name: "wontfix",
|
||
|
Color: "ffffff",
|
||
|
Description: "This will not be worked on",
|
||
|
},
|
||
|
}, labels)
|
||
6 years ago
|
|
||
|
releases, err := downloader.GetReleases()
|
||
|
assert.NoError(t, err)
|
||
3 years ago
|
assertReleasesEqual(t, []*base.Release{
|
||
6 years ago
|
{
|
||
|
TagName: "v0.9.99",
|
||
|
TargetCommitish: "master",
|
||
5 years ago
|
Name: "First Release",
|
||
|
Body: "A test release",
|
||
|
Created: time.Date(2019, 11, 9, 16, 49, 21, 0, time.UTC),
|
||
|
Published: time.Date(2019, 11, 12, 20, 12, 10, 0, time.UTC),
|
||
|
PublisherID: 1669571,
|
||
|
PublisherName: "mrsdizzie",
|
||
6 years ago
|
},
|
||
3 years ago
|
}, releases)
|
||
6 years ago
|
|
||
|
// downloader.GetIssues()
|
||
5 years ago
|
issues, isEnd, err := downloader.GetIssues(1, 2)
|
||
6 years ago
|
assert.NoError(t, err)
|
||
6 years ago
|
assert.False(t, isEnd)
|
||
3 years ago
|
assertIssuesEqual(t, []*base.Issue{
|
||
6 years ago
|
{
|
||
5 years ago
|
Number: 1,
|
||
|
Title: "Please add an animated gif icon to the merge button",
|
||
|
Content: "I just want the merge button to hurt my eyes a little. \xF0\x9F\x98\x9D ",
|
||
|
Milestone: "1.0.0",
|
||
|
PosterID: 18600385,
|
||
|
PosterName: "guillep2k",
|
||
6 years ago
|
State: "closed",
|
||
5 years ago
|
Created: time.Date(2019, 11, 9, 17, 0, 29, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2019, 11, 12, 20, 29, 53, 0, time.UTC),
|
||
6 years ago
|
Labels: []*base.Label{
|
||
|
{
|
||
5 years ago
|
Name: "bug",
|
||
|
Color: "d73a4a",
|
||
|
Description: "Something isn't working",
|
||
6 years ago
|
},
|
||
|
{
|
||
5 years ago
|
Name: "good first issue",
|
||
|
Color: "7057ff",
|
||
|
Description: "Good for newcomers",
|
||
6 years ago
|
},
|
||
|
},
|
||
5 years ago
|
Reactions: []*base.Reaction{
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "+1",
|
||
|
},
|
||
6 years ago
|
},
|
||
3 years ago
|
Closed: timePtr(time.Date(2019, 11, 12, 20, 22, 22, 0, time.UTC)),
|
||
6 years ago
|
},
|
||
|
{
|
||
5 years ago
|
Number: 2,
|
||
|
Title: "Test issue",
|
||
|
Content: "This is test issue 2, do not touch!",
|
||
|
Milestone: "1.1.0",
|
||
|
PosterID: 1669571,
|
||
|
PosterName: "mrsdizzie",
|
||
5 years ago
|
State: "closed",
|
||
5 years ago
|
Created: time.Date(2019, 11, 12, 21, 0, 6, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2019, 11, 12, 22, 7, 14, 0, time.UTC),
|
||
6 years ago
|
Labels: []*base.Label{
|
||
|
{
|
||
5 years ago
|
Name: "duplicate",
|
||
|
Color: "cfd3d7",
|
||
|
Description: "This issue or pull request already exists",
|
||
6 years ago
|
},
|
||
|
},
|
||
5 years ago
|
Reactions: []*base.Reaction{
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "heart",
|
||
|
},
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "laugh",
|
||
|
},
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "-1",
|
||
|
},
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "confused",
|
||
|
},
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "hooray",
|
||
|
},
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "+1",
|
||
|
},
|
||
6 years ago
|
},
|
||
3 years ago
|
Closed: timePtr(time.Date(2019, 11, 12, 21, 1, 31, 0, time.UTC)),
|
||
6 years ago
|
},
|
||
|
}, issues)
|
||
|
|
||
|
// downloader.GetComments()
|
||
3 years ago
|
comments, _, err := downloader.GetComments(base.GetCommentOptions{
|
||
3 years ago
|
Context: base.BasicIssueContext(2),
|
||
3 years ago
|
})
|
||
6 years ago
|
assert.NoError(t, err)
|
||
3 years ago
|
assertCommentsEqual(t, []*base.Comment{
|
||
6 years ago
|
{
|
||
5 years ago
|
IssueIndex: 2,
|
||
|
PosterID: 1669571,
|
||
|
PosterName: "mrsdizzie",
|
||
|
Created: time.Date(2019, 11, 12, 21, 0, 13, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2019, 11, 12, 21, 0, 13, 0, time.UTC),
|
||
5 years ago
|
Content: "This is a comment",
|
||
5 years ago
|
Reactions: []*base.Reaction{
|
||
|
{
|
||
|
UserID: 1669571,
|
||
|
UserName: "mrsdizzie",
|
||
|
Content: "+1",
|
||
|
},
|
||
6 years ago
|
},
|
||
|
},
|
||
|
{
|
||
5 years ago
|
IssueIndex: 2,
|
||
|
PosterID: 1669571,
|
||
|
PosterName: "mrsdizzie",
|
||
|
Created: time.Date(2019, 11, 12, 22, 7, 14, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2019, 11, 12, 22, 7, 14, 0, time.UTC),
|
||
5 years ago
|
Content: "A second comment",
|
||
5 years ago
|
Reactions: nil,
|
||
6 years ago
|
},
|
||
3 years ago
|
}, comments)
|
||
6 years ago
|
|
||
|
// downloader.GetPullRequests()
|
||
4 years ago
|
prs, _, err := downloader.GetPullRequests(1, 2)
|
||
6 years ago
|
assert.NoError(t, err)
|
||
3 years ago
|
assertPullRequestsEqual(t, []*base.PullRequest{
|
||
6 years ago
|
{
|
||
5 years ago
|
Number: 3,
|
||
|
Title: "Update README.md",
|
||
|
Content: "add warning to readme",
|
||
|
Milestone: "1.1.0",
|
||
|
PosterID: 1669571,
|
||
|
PosterName: "mrsdizzie",
|
||
6 years ago
|
State: "closed",
|
||
5 years ago
|
Created: time.Date(2019, 11, 12, 21, 21, 43, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2019, 11, 12, 21, 39, 28, 0, time.UTC),
|
||
6 years ago
|
Labels: []*base.Label{
|
||
|
{
|
||
5 years ago
|
Name: "documentation",
|
||
|
Color: "0075ca",
|
||
|
Description: "Improvements or additions to documentation",
|
||
6 years ago
|
},
|
||
|
},
|
||
5 years ago
|
PatchURL: "https://github.com/go-gitea/test_repo/pull/3.patch",
|
||
6 years ago
|
Head: base.PullRequestBranch{
|
||
5 years ago
|
Ref: "master",
|
||
|
CloneURL: "https://github.com/mrsdizzie/test_repo.git",
|
||
|
SHA: "076160cf0b039f13e5eff19619932d181269414b",
|
||
|
RepoName: "test_repo",
|
||
|
|
||
|
OwnerName: "mrsdizzie",
|
||
6 years ago
|
},
|
||
|
Base: base.PullRequestBranch{
|
||
|
Ref: "master",
|
||
5 years ago
|
SHA: "72866af952e98d02a73003501836074b286a78f6",
|
||
6 years ago
|
OwnerName: "go-gitea",
|
||
5 years ago
|
RepoName: "test_repo",
|
||
6 years ago
|
},
|
||
3 years ago
|
Closed: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)),
|
||
6 years ago
|
Merged: true,
|
||
3 years ago
|
MergedTime: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)),
|
||
5 years ago
|
MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||
3 years ago
|
Context: base.BasicIssueContext(3),
|
||
6 years ago
|
},
|
||
|
{
|
||
5 years ago
|
Number: 4,
|
||
|
Title: "Test branch",
|
||
|
Content: "do not merge this PR",
|
||
6 years ago
|
Milestone: "1.0.0",
|
||
5 years ago
|
PosterID: 1669571,
|
||
|
PosterName: "mrsdizzie",
|
||
|
State: "open",
|
||
|
Created: time.Date(2019, 11, 12, 21, 54, 18, 0, time.UTC),
|
||
5 years ago
|
Updated: time.Date(2020, 1, 4, 11, 30, 1, 0, time.UTC),
|
||
6 years ago
|
Labels: []*base.Label{
|
||
|
{
|
||
5 years ago
|
Name: "bug",
|
||
|
Color: "d73a4a",
|
||
|
Description: "Something isn't working",
|
||
6 years ago
|
},
|
||
|
},
|
||
5 years ago
|
PatchURL: "https://github.com/go-gitea/test_repo/pull/4.patch",
|
||
6 years ago
|
Head: base.PullRequestBranch{
|
||
5 years ago
|
Ref: "test-branch",
|
||
|
SHA: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
RepoName: "test_repo",
|
||
|
OwnerName: "mrsdizzie",
|
||
|
CloneURL: "https://github.com/mrsdizzie/test_repo.git",
|
||
6 years ago
|
},
|
||
|
Base: base.PullRequestBranch{
|
||
5 years ago
|
Ref: "master",
|
||
|
SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
|
||
6 years ago
|
OwnerName: "go-gitea",
|
||
5 years ago
|
RepoName: "test_repo",
|
||
6 years ago
|
},
|
||
5 years ago
|
Merged: false,
|
||
|
MergeCommitSHA: "565d1208f5fffdc1c5ae1a2436491eb9a5e4ebae",
|
||
5 years ago
|
Reactions: []*base.Reaction{
|
||
|
{
|
||
|
UserID: 81045,
|
||
|
UserName: "lunny",
|
||
|
Content: "heart",
|
||
|
},
|
||
|
{
|
||
|
UserID: 81045,
|
||
|
UserName: "lunny",
|
||
|
Content: "+1",
|
||
|
},
|
||
|
},
|
||
3 years ago
|
Context: base.BasicIssueContext(4),
|
||
6 years ago
|
},
|
||
|
}, prs)
|
||
5 years ago
|
|
||
3 years ago
|
reviews, err := downloader.GetReviews(base.BasicIssueContext(3))
|
||
5 years ago
|
assert.NoError(t, err)
|
||
3 years ago
|
assertReviewsEqual(t, []*base.Review{
|
||
5 years ago
|
{
|
||
|
ID: 315859956,
|
||
|
IssueIndex: 3,
|
||
|
ReviewerID: 42128690,
|
||
|
ReviewerName: "jolheiser",
|
||
|
CommitID: "076160cf0b039f13e5eff19619932d181269414b",
|
||
|
CreatedAt: time.Date(2019, 11, 12, 21, 35, 24, 0, time.UTC),
|
||
|
State: base.ReviewStateApproved,
|
||
|
},
|
||
|
{
|
||
|
ID: 315860062,
|
||
|
IssueIndex: 3,
|
||
|
ReviewerID: 1824502,
|
||
|
ReviewerName: "zeripath",
|
||
|
CommitID: "076160cf0b039f13e5eff19619932d181269414b",
|
||
|
CreatedAt: time.Date(2019, 11, 12, 21, 35, 36, 0, time.UTC),
|
||
|
State: base.ReviewStateApproved,
|
||
|
},
|
||
|
{
|
||
|
ID: 315861440,
|
||
|
IssueIndex: 3,
|
||
|
ReviewerID: 165205,
|
||
|
ReviewerName: "lafriks",
|
||
|
CommitID: "076160cf0b039f13e5eff19619932d181269414b",
|
||
|
CreatedAt: time.Date(2019, 11, 12, 21, 38, 00, 0, time.UTC),
|
||
|
State: base.ReviewStateApproved,
|
||
|
},
|
||
|
}, reviews)
|
||
|
|
||
3 years ago
|
reviews, err = downloader.GetReviews(base.BasicIssueContext(4))
|
||
5 years ago
|
assert.NoError(t, err)
|
||
3 years ago
|
assertReviewsEqual(t, []*base.Review{
|
||
5 years ago
|
{
|
||
|
ID: 338338740,
|
||
|
IssueIndex: 4,
|
||
|
ReviewerID: 81045,
|
||
|
ReviewerName: "lunny",
|
||
|
CommitID: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
CreatedAt: time.Date(2020, 01, 04, 05, 33, 18, 0, time.UTC),
|
||
|
State: base.ReviewStateApproved,
|
||
|
Comments: []*base.ReviewComment{
|
||
|
{
|
||
|
ID: 363017488,
|
||
|
Content: "This is a good pull request.",
|
||
|
TreePath: "README.md",
|
||
|
DiffHunk: "@@ -1,2 +1,4 @@\n # test_repo\n Test repository for testing migration from github to gitea\n+",
|
||
|
Position: 3,
|
||
|
CommitID: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
PosterID: 81045,
|
||
|
CreatedAt: time.Date(2020, 01, 04, 05, 33, 06, 0, time.UTC),
|
||
|
UpdatedAt: time.Date(2020, 01, 04, 05, 33, 18, 0, time.UTC),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
ID: 338339651,
|
||
|
IssueIndex: 4,
|
||
|
ReviewerID: 81045,
|
||
|
ReviewerName: "lunny",
|
||
|
CommitID: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
CreatedAt: time.Date(2020, 01, 04, 06, 07, 06, 0, time.UTC),
|
||
|
State: base.ReviewStateChangesRequested,
|
||
|
Content: "Don't add more reviews",
|
||
|
},
|
||
|
{
|
||
|
ID: 338349019,
|
||
|
IssueIndex: 4,
|
||
|
ReviewerID: 81045,
|
||
|
ReviewerName: "lunny",
|
||
|
CommitID: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
CreatedAt: time.Date(2020, 01, 04, 11, 21, 41, 0, time.UTC),
|
||
|
State: base.ReviewStateCommented,
|
||
|
Comments: []*base.ReviewComment{
|
||
|
{
|
||
|
ID: 363029944,
|
||
|
Content: "test a single comment.",
|
||
|
TreePath: "LICENSE",
|
||
|
DiffHunk: "@@ -19,3 +19,5 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n+",
|
||
|
Position: 4,
|
||
|
CommitID: "2be9101c543658591222acbee3eb799edfc3853d",
|
||
|
PosterID: 81045,
|
||
|
CreatedAt: time.Date(2020, 01, 04, 11, 21, 41, 0, time.UTC),
|
||
|
UpdatedAt: time.Date(2020, 01, 04, 11, 21, 41, 0, time.UTC),
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}, reviews)
|
||
6 years ago
|
}
|