本站源代码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

472 lines
14KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Copyright 2018 Jonas Franz. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package migrations
  6. import (
  7. "testing"
  8. "time"
  9. "code.gitea.io/gitea/modules/migrations/base"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func assertMilestoneEqual(t *testing.T, title, dueOn, created, updated, closed, state string, ms *base.Milestone) {
  13. var tmPtr *time.Time
  14. if dueOn != "" {
  15. tm, err := time.Parse("2006-01-02 15:04:05 -0700 MST", dueOn)
  16. assert.NoError(t, err)
  17. tmPtr = &tm
  18. }
  19. var (
  20. createdTM time.Time
  21. updatedTM *time.Time
  22. closedTM *time.Time
  23. )
  24. if created != "" {
  25. var err error
  26. createdTM, err = time.Parse("2006-01-02 15:04:05 -0700 MST", created)
  27. assert.NoError(t, err)
  28. }
  29. if updated != "" {
  30. updatedTemp, err := time.Parse("2006-01-02 15:04:05 -0700 MST", updated)
  31. assert.NoError(t, err)
  32. updatedTM = &updatedTemp
  33. }
  34. if closed != "" {
  35. closedTemp, err := time.Parse("2006-01-02 15:04:05 -0700 MST", closed)
  36. assert.NoError(t, err)
  37. closedTM = &closedTemp
  38. }
  39. assert.EqualValues(t, &base.Milestone{
  40. Title: title,
  41. Deadline: tmPtr,
  42. State: state,
  43. Created: createdTM,
  44. Updated: updatedTM,
  45. Closed: closedTM,
  46. }, ms)
  47. }
  48. func assertLabelEqual(t *testing.T, name, color string, label *base.Label) {
  49. assert.EqualValues(t, &base.Label{
  50. Name: name,
  51. Color: color,
  52. }, label)
  53. }
  54. func TestGitHubDownloadRepo(t *testing.T) {
  55. downloader := NewGithubDownloaderV3("", "", "go-gitea", "gitea")
  56. repo, err := downloader.GetRepoInfo()
  57. assert.NoError(t, err)
  58. assert.EqualValues(t, &base.Repository{
  59. Name: "gitea",
  60. Owner: "go-gitea",
  61. Description: "Git with a cup of tea, painless self-hosted git service",
  62. CloneURL: "https://github.com/go-gitea/gitea.git",
  63. OriginalURL: "https://github.com/go-gitea/gitea",
  64. }, repo)
  65. topics, err := downloader.GetTopics()
  66. assert.NoError(t, err)
  67. assert.Contains(t, topics, "gitea")
  68. milestones, err := downloader.GetMilestones()
  69. assert.NoError(t, err)
  70. // before this tool release, we have 39 milestones on github.com/go-gitea/gitea
  71. assert.True(t, len(milestones) >= 39)
  72. for _, milestone := range milestones {
  73. switch milestone.Title {
  74. case "1.0.0":
  75. assertMilestoneEqual(t, "1.0.0", "2016-12-23 08:00:00 +0000 UTC",
  76. "2016-11-02 18:06:55 +0000 UTC",
  77. "2016-12-29 10:26:00 +0000 UTC",
  78. "2016-12-24 00:40:56 +0000 UTC",
  79. "closed", milestone)
  80. case "1.1.0":
  81. assertMilestoneEqual(t, "1.1.0", "2017-02-24 08:00:00 +0000 UTC",
  82. "2016-11-03 08:40:10 +0000 UTC",
  83. "2017-06-15 05:04:36 +0000 UTC",
  84. "2017-03-09 21:22:21 +0000 UTC",
  85. "closed", milestone)
  86. case "1.2.0":
  87. assertMilestoneEqual(t, "1.2.0", "2017-04-24 07:00:00 +0000 UTC",
  88. "2016-11-03 08:40:15 +0000 UTC",
  89. "2017-12-10 02:43:29 +0000 UTC",
  90. "2017-10-12 08:24:28 +0000 UTC",
  91. "closed", milestone)
  92. case "1.3.0":
  93. assertMilestoneEqual(t, "1.3.0", "2017-11-29 08:00:00 +0000 UTC",
  94. "2017-03-03 08:08:59 +0000 UTC",
  95. "2017-12-04 07:48:44 +0000 UTC",
  96. "2017-11-29 18:39:00 +0000 UTC",
  97. "closed", milestone)
  98. case "1.4.0":
  99. assertMilestoneEqual(t, "1.4.0", "2018-01-25 08:00:00 +0000 UTC",
  100. "2017-08-23 11:02:37 +0000 UTC",
  101. "2018-03-25 20:01:56 +0000 UTC",
  102. "2018-03-25 20:01:56 +0000 UTC",
  103. "closed", milestone)
  104. case "1.5.0":
  105. assertMilestoneEqual(t, "1.5.0", "2018-06-15 07:00:00 +0000 UTC",
  106. "2017-12-30 04:21:56 +0000 UTC",
  107. "2018-09-05 16:34:22 +0000 UTC",
  108. "2018-08-11 08:45:01 +0000 UTC",
  109. "closed", milestone)
  110. case "1.6.0":
  111. assertMilestoneEqual(t, "1.6.0", "2018-09-25 07:00:00 +0000 UTC",
  112. "2018-05-11 05:37:01 +0000 UTC",
  113. "2019-01-27 19:21:22 +0000 UTC",
  114. "2018-11-23 13:23:16 +0000 UTC",
  115. "closed", milestone)
  116. case "1.7.0":
  117. assertMilestoneEqual(t, "1.7.0", "2018-12-25 08:00:00 +0000 UTC",
  118. "2018-08-28 14:20:14 +0000 UTC",
  119. "2019-01-27 11:30:24 +0000 UTC",
  120. "2019-01-23 08:58:23 +0000 UTC",
  121. "closed", milestone)
  122. }
  123. }
  124. labels, err := downloader.GetLabels()
  125. assert.NoError(t, err)
  126. assert.True(t, len(labels) >= 48)
  127. for _, l := range labels {
  128. switch l.Name {
  129. case "backport/v1.7":
  130. assertLabelEqual(t, "backport/v1.7", "fbca04", l)
  131. case "backport/v1.8":
  132. assertLabelEqual(t, "backport/v1.8", "fbca04", l)
  133. case "kind/api":
  134. assertLabelEqual(t, "kind/api", "5319e7", l)
  135. case "kind/breaking":
  136. assertLabelEqual(t, "kind/breaking", "fbca04", l)
  137. case "kind/bug":
  138. assertLabelEqual(t, "kind/bug", "ee0701", l)
  139. case "kind/docs":
  140. assertLabelEqual(t, "kind/docs", "c2e0c6", l)
  141. case "kind/enhancement":
  142. assertLabelEqual(t, "kind/enhancement", "84b6eb", l)
  143. case "kind/feature":
  144. assertLabelEqual(t, "kind/feature", "006b75", l)
  145. }
  146. }
  147. releases, err := downloader.GetReleases()
  148. assert.NoError(t, err)
  149. assert.EqualValues(t, []*base.Release{
  150. {
  151. TagName: "v0.9.99",
  152. TargetCommitish: "master",
  153. Name: "fork",
  154. Body: "Forked source from Gogs into Gitea\n",
  155. Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
  156. Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
  157. PublisherID: 4726179,
  158. PublisherName: "bkcsoft",
  159. },
  160. }, releases[len(releases)-1:])
  161. // downloader.GetIssues()
  162. issues, isEnd, err := downloader.GetIssues(1, 8)
  163. assert.NoError(t, err)
  164. assert.EqualValues(t, 3, len(issues))
  165. assert.False(t, isEnd)
  166. var (
  167. closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC)
  168. closed7 = time.Date(2019, 7, 8, 8, 20, 23, 0, time.UTC)
  169. )
  170. assert.EqualValues(t, []*base.Issue{
  171. {
  172. Number: 6,
  173. Title: "Contribution system: History heatmap for user",
  174. Content: "Hi guys,\r\n\r\nI think that is a possible feature, a history heatmap similar to github or gitlab.\r\nActually exists a plugin called Calendar HeatMap. I used this on mine project to heat application log and worked fine here.\r\nThen, is only a idea, what you think? :)\r\n\r\nhttp://cal-heatmap.com/\r\nhttps://github.com/wa0x6e/cal-heatmap\r\n\r\nReference: https://github.com/gogits/gogs/issues/1640",
  175. Milestone: "1.7.0",
  176. PosterID: 1520407,
  177. PosterName: "joubertredrat",
  178. State: "closed",
  179. Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC),
  180. Labels: []*base.Label{
  181. {
  182. Name: "kind/feature",
  183. Color: "006b75",
  184. },
  185. {
  186. Name: "kind/ui",
  187. Color: "fef2c0",
  188. },
  189. },
  190. Reactions: &base.Reactions{
  191. TotalCount: 0,
  192. PlusOne: 0,
  193. MinusOne: 0,
  194. Laugh: 0,
  195. Confused: 0,
  196. Heart: 0,
  197. Hooray: 0,
  198. },
  199. Closed: &closed1,
  200. },
  201. {
  202. Number: 7,
  203. Title: "display page revisions on wiki",
  204. Content: "Hi guys,\r\n\r\nWiki on Gogs is very fine, I liked a lot, but I think that is good idea to be possible see other revisions from page as a page history.\r\n\r\nWhat you think?\r\n\r\nReference: https://github.com/gogits/gogs/issues/2991",
  205. Milestone: "1.10.0",
  206. PosterID: 1520407,
  207. PosterName: "joubertredrat",
  208. State: "closed",
  209. Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC),
  210. Labels: []*base.Label{
  211. {
  212. Name: "kind/feature",
  213. Color: "006b75",
  214. },
  215. {
  216. Name: "reviewed/confirmed",
  217. Color: "8d9b12",
  218. Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
  219. },
  220. },
  221. Reactions: &base.Reactions{
  222. TotalCount: 6,
  223. PlusOne: 5,
  224. MinusOne: 0,
  225. Laugh: 0,
  226. Confused: 1,
  227. Heart: 0,
  228. Hooray: 0,
  229. },
  230. Closed: &closed7,
  231. },
  232. {
  233. Number: 8,
  234. Title: "audit logs",
  235. Content: "Hi,\r\n\r\nI think that is good idea to have user operation log to admin see what the user is doing at Gogs. Similar to example below\r\n\r\n| user | operation | information |\r\n| --- | --- | --- |\r\n| joubertredrat | repo.create | Create repo MyProjectData |\r\n| joubertredrat | user.settings | Edit settings |\r\n| tboerger | repo.fork | Create Fork from MyProjectData to ForkMyProjectData |\r\n| bkcsoft | repo.remove | Remove repo MySource |\r\n| tboerger | admin.auth | Edit auth LDAP org-connection |\r\n\r\nThis resource can be used on user page too, as user activity, set that log row is public (repo._) or private (user._, admin.*) and display only public activity.\r\n\r\nWhat you think?\r\n\r\n[Chat summary from March 14, 2017](https://github.com/go-gitea/gitea/issues/8#issuecomment-286463807)\r\n\r\nReferences:\r\nhttps://github.com/gogits/gogs/issues/3016",
  236. Milestone: "1.x.x",
  237. PosterID: 1520407,
  238. PosterName: "joubertredrat",
  239. State: "open",
  240. Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC),
  241. Labels: []*base.Label{
  242. {
  243. Name: "kind/feature",
  244. Color: "006b75",
  245. },
  246. {
  247. Name: "kind/proposal",
  248. Color: "5319e7",
  249. },
  250. },
  251. Reactions: &base.Reactions{
  252. TotalCount: 9,
  253. PlusOne: 8,
  254. MinusOne: 0,
  255. Laugh: 0,
  256. Confused: 0,
  257. Heart: 1,
  258. Hooray: 0,
  259. },
  260. },
  261. }, issues)
  262. // downloader.GetComments()
  263. comments, err := downloader.GetComments(6)
  264. assert.NoError(t, err)
  265. assert.EqualValues(t, 35, len(comments))
  266. assert.EqualValues(t, []*base.Comment{
  267. {
  268. IssueIndex: 6,
  269. PosterID: 4726179,
  270. PosterName: "bkcsoft",
  271. Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC),
  272. Content: `I would prefer a solution that is in the backend, unless it's required to have it update without reloading. Unfortunately I can't seem to find anything that does that :unamused:
  273. Also this would _require_ caching, since it will fetch huge amounts of data from disk...
  274. `,
  275. Reactions: &base.Reactions{
  276. TotalCount: 2,
  277. PlusOne: 2,
  278. MinusOne: 0,
  279. Laugh: 0,
  280. Confused: 0,
  281. Heart: 0,
  282. Hooray: 0,
  283. },
  284. },
  285. {
  286. IssueIndex: 6,
  287. PosterID: 1520407,
  288. PosterName: "joubertredrat",
  289. Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC),
  290. Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this.
  291. In my case I use ajax to get data, but build on frontend anyway
  292. `,
  293. Reactions: &base.Reactions{
  294. TotalCount: 0,
  295. PlusOne: 0,
  296. MinusOne: 0,
  297. Laugh: 0,
  298. Confused: 0,
  299. Heart: 0,
  300. Hooray: 0,
  301. },
  302. },
  303. {
  304. IssueIndex: 6,
  305. PosterID: 1799009,
  306. PosterName: "xinity",
  307. Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC),
  308. Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
  309. something like in the latest 15days could be enough don't you think ?
  310. `,
  311. Reactions: &base.Reactions{
  312. TotalCount: 2,
  313. PlusOne: 2,
  314. MinusOne: 0,
  315. Laugh: 0,
  316. Confused: 0,
  317. Heart: 0,
  318. Hooray: 0,
  319. },
  320. },
  321. }, comments[:3])
  322. // downloader.GetPullRequests()
  323. prs, err := downloader.GetPullRequests(1, 3)
  324. assert.NoError(t, err)
  325. assert.EqualValues(t, 3, len(prs))
  326. closed1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  327. var (
  328. closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  329. closed3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  330. )
  331. var (
  332. merged1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  333. merged2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  334. merged3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  335. )
  336. assert.EqualValues(t, []*base.PullRequest{
  337. {
  338. Number: 1,
  339. Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"",
  340. Content: "",
  341. Milestone: "1.0.0",
  342. PosterID: 7011819,
  343. PosterName: "andreynering",
  344. State: "closed",
  345. Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC),
  346. Labels: []*base.Label{
  347. {
  348. Name: "kind/enhancement",
  349. Color: "84b6eb",
  350. },
  351. {
  352. Name: "lgtm/done",
  353. Color: "0e8a16",
  354. },
  355. },
  356. PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch",
  357. Head: base.PullRequestBranch{
  358. Ref: "import-paths",
  359. SHA: "1b0ec3208db8501acba44a137c009a5a126ebaa9",
  360. OwnerName: "andreynering",
  361. },
  362. Base: base.PullRequestBranch{
  363. Ref: "master",
  364. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  365. OwnerName: "go-gitea",
  366. RepoName: "gitea",
  367. },
  368. Closed: &closed1,
  369. Merged: true,
  370. MergedTime: &merged1,
  371. MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab",
  372. },
  373. {
  374. Number: 2,
  375. Title: "Fix sender of issue notifications",
  376. Content: "It is the FROM field in mailer configuration that needs be used,\r\nnot the USER field, which is for authentication.\r\n\r\nMigrated from https://github.com/gogits/gogs/pull/3616\r\n",
  377. Milestone: "1.0.0",
  378. PosterID: 289678,
  379. PosterName: "strk",
  380. State: "closed",
  381. Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC),
  382. Labels: []*base.Label{
  383. {
  384. Name: "kind/bug",
  385. Color: "ee0701",
  386. },
  387. {
  388. Name: "lgtm/done",
  389. Color: "0e8a16",
  390. },
  391. },
  392. PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch",
  393. Head: base.PullRequestBranch{
  394. Ref: "proper-from-on-issue-mail",
  395. SHA: "af03d00780a6ee70c58e135c6679542cde4f8d50",
  396. RepoName: "gogs",
  397. OwnerName: "strk",
  398. CloneURL: "https://github.com/strk/gogs.git",
  399. },
  400. Base: base.PullRequestBranch{
  401. Ref: "develop",
  402. SHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  403. OwnerName: "go-gitea",
  404. RepoName: "gitea",
  405. },
  406. Closed: &closed2,
  407. Merged: true,
  408. MergedTime: &merged2,
  409. MergeCommitSHA: "d8de2beb5b92d02a0597ba7c7803839380666653",
  410. },
  411. {
  412. Number: 3,
  413. Title: "Use proper url for libravatar dep",
  414. Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n",
  415. Milestone: "1.0.0",
  416. PosterID: 289678,
  417. PosterName: "strk",
  418. State: "closed",
  419. Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC),
  420. Labels: []*base.Label{
  421. {
  422. Name: "kind/enhancement",
  423. Color: "84b6eb",
  424. },
  425. {
  426. Name: "lgtm/done",
  427. Color: "0e8a16",
  428. },
  429. },
  430. PatchURL: "https://github.com/go-gitea/gitea/pull/3.patch",
  431. Head: base.PullRequestBranch{
  432. Ref: "libravatar-proper-url",
  433. SHA: "d59a48a2550abd4129b96d38473941b895a4859b",
  434. RepoName: "gogs",
  435. OwnerName: "strk",
  436. CloneURL: "https://github.com/strk/gogs.git",
  437. },
  438. Base: base.PullRequestBranch{
  439. Ref: "develop",
  440. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  441. OwnerName: "go-gitea",
  442. RepoName: "gitea",
  443. },
  444. Closed: &closed3,
  445. Merged: true,
  446. MergedTime: &merged3,
  447. MergeCommitSHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  448. },
  449. }, prs)
  450. }
上海开阖软件有限公司 沪ICP备12045867号-1