summaryrefslogtreecommitdiffstats
path: root/services/migrations/onedev_test.go
blob: 80c26130cc697361252bf0f34f4d5774bd1b1f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package migrations

import (
	"context"
	"net/http"
	"net/url"
	"testing"
	"time"

	base "code.gitea.io/gitea/modules/migration"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestOneDevDownloadRepo(t *testing.T) {
	resp, err := http.Get("https://code.onedev.io/projects/go-gitea-test_repo")
	if err != nil || resp.StatusCode != http.StatusOK {
		t.Skipf("Can't access test repo, skipping %s", t.Name())
	}

	u, _ := url.Parse("https://code.onedev.io")
	downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
	if err != nil {
		t.Fatalf("NewOneDevDownloader is nil: %v", err)
	}
	repo, err := downloader.GetRepoInfo()
	require.NoError(t, err)
	assertRepositoryEqual(t, &base.Repository{
		Name:        "go-gitea-test_repo",
		Owner:       "",
		Description: "Test repository for testing migration from OneDev to gitea",
		CloneURL:    "https://code.onedev.io/go-gitea-test_repo",
		OriginalURL: "https://code.onedev.io/projects/go-gitea-test_repo",
	}, repo)

	milestones, err := downloader.GetMilestones()
	require.NoError(t, err)
	deadline := time.Unix(1620086400, 0)
	assertMilestonesEqual(t, []*base.Milestone{
		{
			Title:    "1.0.0",
			Deadline: &deadline,
			Closed:   &deadline,
		},
		{
			Title:       "1.1.0",
			Description: "next things?",
		},
	}, milestones)

	labels, err := downloader.GetLabels()
	require.NoError(t, err)
	assert.Len(t, labels, 6)

	issues, isEnd, err := downloader.GetIssues(1, 2)
	require.NoError(t, err)
	assert.False(t, isEnd)
	assertIssuesEqual(t, []*base.Issue{
		{
			Number:     4,
			Title:      "Hi there",
			Content:    "an issue not assigned to a milestone",
			PosterName: "User 336",
			State:      "open",
			Created:    time.Unix(1628549776, 734000000),
			Updated:    time.Unix(1628549776, 734000000),
			Labels: []*base.Label{
				{
					Name: "Improvement",
				},
			},
			ForeignIndex: 398,
			Context:      onedevIssueContext{IsPullRequest: false},
		},
		{
			Number:     3,
			Title:      "Add an awesome feature",
			Content:    "just another issue to test against",
			PosterName: "User 336",
			State:      "open",
			Milestone:  "1.1.0",
			Created:    time.Unix(1628549749, 878000000),
			Updated:    time.Unix(1628549749, 878000000),
			Labels: []*base.Label{
				{
					Name: "New Feature",
				},
			},
			ForeignIndex: 397,
			Context:      onedevIssueContext{IsPullRequest: false},
		},
	}, issues)

	comments, _, err := downloader.GetComments(&base.Issue{
		Number:       4,
		ForeignIndex: 398,
		Context:      onedevIssueContext{IsPullRequest: false},
	})
	require.NoError(t, err)
	assertCommentsEqual(t, []*base.Comment{
		{
			IssueIndex: 4,
			PosterName: "User 336",
			Created:    time.Unix(1628549791, 128000000),
			Updated:    time.Unix(1628549791, 128000000),
			Content:    "it has a comment\n\nEDIT: that got edited",
		},
	}, comments)

	prs, _, err := downloader.GetPullRequests(1, 1)
	require.NoError(t, err)
	assertPullRequestsEqual(t, []*base.PullRequest{
		{
			Number:     5,
			Title:      "Pull to add a new file",
			Content:    "just do some git stuff",
			PosterName: "User 336",
			State:      "open",
			Created:    time.Unix(1628550076, 25000000),
			Updated:    time.Unix(1628550076, 25000000),
			Head: base.PullRequestBranch{
				Ref:      "branch-for-a-pull",
				SHA:      "343deffe3526b9bc84e873743ff7f6e6d8b827c0",
				RepoName: "go-gitea-test_repo",
			},
			Base: base.PullRequestBranch{
				Ref:      "master",
				SHA:      "f32b0a9dfd09a60f616f29158f772cedd89942d2",
				RepoName: "go-gitea-test_repo",
			},
			ForeignIndex: 186,
			Context:      onedevIssueContext{IsPullRequest: true},
		},
	}, prs)

	rvs, err := downloader.GetReviews(&base.PullRequest{Number: 5, ForeignIndex: 186})
	require.NoError(t, err)
	assertReviewsEqual(t, []*base.Review{
		{
			IssueIndex:   5,
			ReviewerName: "User 317",
			State:        "PENDING",
		},
	}, rvs)
}