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.

github_test.go 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. },
  158. }, releases[len(releases)-1:])
  159. // downloader.GetIssues()
  160. issues, isEnd, err := downloader.GetIssues(1, 8)
  161. assert.NoError(t, err)
  162. assert.EqualValues(t, 3, len(issues))
  163. assert.False(t, isEnd)
  164. var (
  165. closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC)
  166. closed7 = time.Date(2019, 7, 8, 8, 20, 23, 0, time.UTC)
  167. )
  168. assert.EqualValues(t, []*base.Issue{
  169. {
  170. Number: 6,
  171. Title: "Contribution system: History heatmap for user",
  172. 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",
  173. Milestone: "1.7.0",
  174. PosterID: 1520407,
  175. PosterName: "joubertredrat",
  176. State: "closed",
  177. Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC),
  178. Labels: []*base.Label{
  179. {
  180. Name: "kind/feature",
  181. Color: "006b75",
  182. },
  183. {
  184. Name: "kind/ui",
  185. Color: "fef2c0",
  186. },
  187. },
  188. Reactions: &base.Reactions{
  189. TotalCount: 0,
  190. PlusOne: 0,
  191. MinusOne: 0,
  192. Laugh: 0,
  193. Confused: 0,
  194. Heart: 0,
  195. Hooray: 0,
  196. },
  197. Closed: &closed1,
  198. },
  199. {
  200. Number: 7,
  201. Title: "display page revisions on wiki",
  202. 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",
  203. Milestone: "1.10.0",
  204. PosterID: 1520407,
  205. PosterName: "joubertredrat",
  206. State: "closed",
  207. Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC),
  208. Labels: []*base.Label{
  209. {
  210. Name: "kind/feature",
  211. Color: "006b75",
  212. },
  213. {
  214. Name: "reviewed/confirmed",
  215. Color: "8d9b12",
  216. Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
  217. },
  218. },
  219. Reactions: &base.Reactions{
  220. TotalCount: 6,
  221. PlusOne: 5,
  222. MinusOne: 0,
  223. Laugh: 0,
  224. Confused: 1,
  225. Heart: 0,
  226. Hooray: 0,
  227. },
  228. Closed: &closed7,
  229. },
  230. {
  231. Number: 8,
  232. Title: "audit logs",
  233. 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",
  234. Milestone: "1.x.x",
  235. PosterID: 1520407,
  236. PosterName: "joubertredrat",
  237. State: "open",
  238. Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC),
  239. Labels: []*base.Label{
  240. {
  241. Name: "kind/feature",
  242. Color: "006b75",
  243. },
  244. {
  245. Name: "kind/proposal",
  246. Color: "5319e7",
  247. },
  248. },
  249. Reactions: &base.Reactions{
  250. TotalCount: 9,
  251. PlusOne: 8,
  252. MinusOne: 0,
  253. Laugh: 0,
  254. Confused: 0,
  255. Heart: 1,
  256. Hooray: 0,
  257. },
  258. },
  259. }, issues)
  260. // downloader.GetComments()
  261. comments, err := downloader.GetComments(6)
  262. assert.NoError(t, err)
  263. assert.EqualValues(t, 35, len(comments))
  264. assert.EqualValues(t, []*base.Comment{
  265. {
  266. IssueIndex: 6,
  267. PosterID: 4726179,
  268. PosterName: "bkcsoft",
  269. Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC),
  270. 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:
  271. Also this would _require_ caching, since it will fetch huge amounts of data from disk...
  272. `,
  273. Reactions: &base.Reactions{
  274. TotalCount: 2,
  275. PlusOne: 2,
  276. MinusOne: 0,
  277. Laugh: 0,
  278. Confused: 0,
  279. Heart: 0,
  280. Hooray: 0,
  281. },
  282. },
  283. {
  284. IssueIndex: 6,
  285. PosterID: 1520407,
  286. PosterName: "joubertredrat",
  287. Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC),
  288. Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this.
  289. In my case I use ajax to get data, but build on frontend anyway
  290. `,
  291. Reactions: &base.Reactions{
  292. TotalCount: 0,
  293. PlusOne: 0,
  294. MinusOne: 0,
  295. Laugh: 0,
  296. Confused: 0,
  297. Heart: 0,
  298. Hooray: 0,
  299. },
  300. },
  301. {
  302. IssueIndex: 6,
  303. PosterID: 1799009,
  304. PosterName: "xinity",
  305. Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC),
  306. Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
  307. something like in the latest 15days could be enough don't you think ?
  308. `,
  309. Reactions: &base.Reactions{
  310. TotalCount: 2,
  311. PlusOne: 2,
  312. MinusOne: 0,
  313. Laugh: 0,
  314. Confused: 0,
  315. Heart: 0,
  316. Hooray: 0,
  317. },
  318. },
  319. }, comments[:3])
  320. // downloader.GetPullRequests()
  321. prs, err := downloader.GetPullRequests(1, 3)
  322. assert.NoError(t, err)
  323. assert.EqualValues(t, 3, len(prs))
  324. closed1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  325. var (
  326. closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  327. closed3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  328. )
  329. var (
  330. merged1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  331. merged2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  332. merged3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  333. )
  334. assert.EqualValues(t, []*base.PullRequest{
  335. {
  336. Number: 1,
  337. Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"",
  338. Content: "",
  339. Milestone: "1.0.0",
  340. PosterID: 7011819,
  341. PosterName: "andreynering",
  342. State: "closed",
  343. Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC),
  344. Labels: []*base.Label{
  345. {
  346. Name: "kind/enhancement",
  347. Color: "84b6eb",
  348. },
  349. {
  350. Name: "lgtm/done",
  351. Color: "0e8a16",
  352. },
  353. },
  354. PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch",
  355. Head: base.PullRequestBranch{
  356. Ref: "import-paths",
  357. SHA: "1b0ec3208db8501acba44a137c009a5a126ebaa9",
  358. OwnerName: "andreynering",
  359. },
  360. Base: base.PullRequestBranch{
  361. Ref: "master",
  362. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  363. OwnerName: "go-gitea",
  364. RepoName: "gitea",
  365. },
  366. Closed: &closed1,
  367. Merged: true,
  368. MergedTime: &merged1,
  369. MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab",
  370. },
  371. {
  372. Number: 2,
  373. Title: "Fix sender of issue notifications",
  374. 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",
  375. Milestone: "1.0.0",
  376. PosterID: 289678,
  377. PosterName: "strk",
  378. State: "closed",
  379. Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC),
  380. Labels: []*base.Label{
  381. {
  382. Name: "kind/bug",
  383. Color: "ee0701",
  384. },
  385. {
  386. Name: "lgtm/done",
  387. Color: "0e8a16",
  388. },
  389. },
  390. PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch",
  391. Head: base.PullRequestBranch{
  392. Ref: "proper-from-on-issue-mail",
  393. SHA: "af03d00780a6ee70c58e135c6679542cde4f8d50",
  394. RepoName: "gogs",
  395. OwnerName: "strk",
  396. CloneURL: "https://github.com/strk/gogs.git",
  397. },
  398. Base: base.PullRequestBranch{
  399. Ref: "develop",
  400. SHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  401. OwnerName: "go-gitea",
  402. RepoName: "gitea",
  403. },
  404. Closed: &closed2,
  405. Merged: true,
  406. MergedTime: &merged2,
  407. MergeCommitSHA: "d8de2beb5b92d02a0597ba7c7803839380666653",
  408. },
  409. {
  410. Number: 3,
  411. Title: "Use proper url for libravatar dep",
  412. Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n",
  413. Milestone: "1.0.0",
  414. PosterID: 289678,
  415. PosterName: "strk",
  416. State: "closed",
  417. Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC),
  418. Labels: []*base.Label{
  419. {
  420. Name: "kind/enhancement",
  421. Color: "84b6eb",
  422. },
  423. {
  424. Name: "lgtm/done",
  425. Color: "0e8a16",
  426. },
  427. },
  428. PatchURL: "https://github.com/go-gitea/gitea/pull/3.patch",
  429. Head: base.PullRequestBranch{
  430. Ref: "libravatar-proper-url",
  431. SHA: "d59a48a2550abd4129b96d38473941b895a4859b",
  432. RepoName: "gogs",
  433. OwnerName: "strk",
  434. CloneURL: "https://github.com/strk/gogs.git",
  435. },
  436. Base: base.PullRequestBranch{
  437. Ref: "develop",
  438. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  439. OwnerName: "go-gitea",
  440. RepoName: "gitea",
  441. },
  442. Closed: &closed3,
  443. Merged: true,
  444. MergedTime: &merged3,
  445. MergeCommitSHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  446. },
  447. }, prs)
  448. }