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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. }, repo)
  64. milestones, err := downloader.GetMilestones()
  65. assert.NoError(t, err)
  66. // before this tool release, we have 39 milestones on github.com/go-gitea/gitea
  67. assert.True(t, len(milestones) >= 39)
  68. for _, milestone := range milestones {
  69. switch milestone.Title {
  70. case "1.0.0":
  71. assertMilestoneEqual(t, "1.0.0", "2016-12-23 08:00:00 +0000 UTC",
  72. "2016-11-02 18:06:55 +0000 UTC",
  73. "2016-12-29 10:26:00 +0000 UTC",
  74. "2016-12-24 00:40:56 +0000 UTC",
  75. "closed", milestone)
  76. case "1.1.0":
  77. assertMilestoneEqual(t, "1.1.0", "2017-02-24 08:00:00 +0000 UTC",
  78. "2016-11-03 08:40:10 +0000 UTC",
  79. "2017-06-15 05:04:36 +0000 UTC",
  80. "2017-03-09 21:22:21 +0000 UTC",
  81. "closed", milestone)
  82. case "1.2.0":
  83. assertMilestoneEqual(t, "1.2.0", "2017-04-24 07:00:00 +0000 UTC",
  84. "2016-11-03 08:40:15 +0000 UTC",
  85. "2017-12-10 02:43:29 +0000 UTC",
  86. "2017-10-12 08:24:28 +0000 UTC",
  87. "closed", milestone)
  88. case "1.3.0":
  89. assertMilestoneEqual(t, "1.3.0", "2017-11-29 08:00:00 +0000 UTC",
  90. "2017-03-03 08:08:59 +0000 UTC",
  91. "2017-12-04 07:48:44 +0000 UTC",
  92. "2017-11-29 18:39:00 +0000 UTC",
  93. "closed", milestone)
  94. case "1.4.0":
  95. assertMilestoneEqual(t, "1.4.0", "2018-01-25 08:00:00 +0000 UTC",
  96. "2017-08-23 11:02:37 +0000 UTC",
  97. "2018-03-25 20:01:56 +0000 UTC",
  98. "2018-03-25 20:01:56 +0000 UTC",
  99. "closed", milestone)
  100. case "1.5.0":
  101. assertMilestoneEqual(t, "1.5.0", "2018-06-15 07:00:00 +0000 UTC",
  102. "2017-12-30 04:21:56 +0000 UTC",
  103. "2018-09-05 16:34:22 +0000 UTC",
  104. "2018-08-11 08:45:01 +0000 UTC",
  105. "closed", milestone)
  106. case "1.6.0":
  107. assertMilestoneEqual(t, "1.6.0", "2018-09-25 07:00:00 +0000 UTC",
  108. "2018-05-11 05:37:01 +0000 UTC",
  109. "2019-01-27 19:21:22 +0000 UTC",
  110. "2018-11-23 13:23:16 +0000 UTC",
  111. "closed", milestone)
  112. case "1.7.0":
  113. assertMilestoneEqual(t, "1.7.0", "2018-12-25 08:00:00 +0000 UTC",
  114. "2018-08-28 14:20:14 +0000 UTC",
  115. "2019-01-27 11:30:24 +0000 UTC",
  116. "2019-01-23 08:58:23 +0000 UTC",
  117. "closed", milestone)
  118. }
  119. }
  120. labels, err := downloader.GetLabels()
  121. assert.NoError(t, err)
  122. assert.True(t, len(labels) >= 48)
  123. for _, l := range labels {
  124. switch l.Name {
  125. case "backport/v1.7":
  126. assertLabelEqual(t, "backport/v1.7", "fbca04", l)
  127. case "backport/v1.8":
  128. assertLabelEqual(t, "backport/v1.8", "fbca04", l)
  129. case "kind/api":
  130. assertLabelEqual(t, "kind/api", "5319e7", l)
  131. case "kind/breaking":
  132. assertLabelEqual(t, "kind/breaking", "fbca04", l)
  133. case "kind/bug":
  134. assertLabelEqual(t, "kind/bug", "ee0701", l)
  135. case "kind/docs":
  136. assertLabelEqual(t, "kind/docs", "c2e0c6", l)
  137. case "kind/enhancement":
  138. assertLabelEqual(t, "kind/enhancement", "84b6eb", l)
  139. case "kind/feature":
  140. assertLabelEqual(t, "kind/feature", "006b75", l)
  141. }
  142. }
  143. releases, err := downloader.GetReleases()
  144. assert.NoError(t, err)
  145. assert.EqualValues(t, []*base.Release{
  146. {
  147. TagName: "v0.9.99",
  148. TargetCommitish: "master",
  149. Name: "fork",
  150. Body: "Forked source from Gogs into Gitea\n",
  151. Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
  152. Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
  153. },
  154. }, releases[len(releases)-1:])
  155. // downloader.GetIssues()
  156. issues, isEnd, err := downloader.GetIssues(1, 8)
  157. assert.NoError(t, err)
  158. assert.EqualValues(t, 3, len(issues))
  159. assert.False(t, isEnd)
  160. var (
  161. closed1 = time.Date(2018, 10, 23, 02, 57, 43, 0, time.UTC)
  162. )
  163. assert.EqualValues(t, []*base.Issue{
  164. {
  165. Number: 6,
  166. Title: "Contribution system: History heatmap for user",
  167. 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",
  168. Milestone: "1.7.0",
  169. PosterName: "joubertredrat",
  170. State: "closed",
  171. Created: time.Date(2016, 11, 02, 18, 51, 55, 0, time.UTC),
  172. Labels: []*base.Label{
  173. {
  174. Name: "kind/feature",
  175. Color: "006b75",
  176. },
  177. {
  178. Name: "kind/ui",
  179. Color: "fef2c0",
  180. },
  181. },
  182. Reactions: &base.Reactions{
  183. TotalCount: 0,
  184. PlusOne: 0,
  185. MinusOne: 0,
  186. Laugh: 0,
  187. Confused: 0,
  188. Heart: 0,
  189. Hooray: 0,
  190. },
  191. Closed: &closed1,
  192. },
  193. {
  194. Number: 7,
  195. Title: "display page revisions on wiki",
  196. 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",
  197. Milestone: "1.x.x",
  198. PosterName: "joubertredrat",
  199. State: "open",
  200. Created: time.Date(2016, 11, 02, 18, 57, 32, 0, time.UTC),
  201. Labels: []*base.Label{
  202. {
  203. Name: "kind/feature",
  204. Color: "006b75",
  205. },
  206. {
  207. Name: "reviewed/confirmed",
  208. Color: "8d9b12",
  209. Description: "Issue has been reviewed and confirmed to be present or accepted to be implemented",
  210. },
  211. },
  212. Reactions: &base.Reactions{
  213. TotalCount: 6,
  214. PlusOne: 5,
  215. MinusOne: 0,
  216. Laugh: 0,
  217. Confused: 1,
  218. Heart: 0,
  219. Hooray: 0,
  220. },
  221. },
  222. {
  223. Number: 8,
  224. Title: "audit logs",
  225. 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",
  226. Milestone: "1.x.x",
  227. PosterName: "joubertredrat",
  228. State: "open",
  229. Created: time.Date(2016, 11, 02, 18, 59, 20, 0, time.UTC),
  230. Labels: []*base.Label{
  231. {
  232. Name: "kind/feature",
  233. Color: "006b75",
  234. },
  235. {
  236. Name: "kind/proposal",
  237. Color: "5319e7",
  238. },
  239. },
  240. Reactions: &base.Reactions{
  241. TotalCount: 9,
  242. PlusOne: 8,
  243. MinusOne: 0,
  244. Laugh: 0,
  245. Confused: 0,
  246. Heart: 1,
  247. Hooray: 0,
  248. },
  249. },
  250. }, issues)
  251. // downloader.GetComments()
  252. comments, err := downloader.GetComments(6)
  253. assert.NoError(t, err)
  254. assert.EqualValues(t, 35, len(comments))
  255. assert.EqualValues(t, []*base.Comment{
  256. {
  257. PosterName: "bkcsoft",
  258. Created: time.Date(2016, 11, 02, 18, 59, 48, 0, time.UTC),
  259. 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:
  260. Also this would _require_ caching, since it will fetch huge amounts of data from disk...
  261. `,
  262. Reactions: &base.Reactions{
  263. TotalCount: 2,
  264. PlusOne: 2,
  265. MinusOne: 0,
  266. Laugh: 0,
  267. Confused: 0,
  268. Heart: 0,
  269. Hooray: 0,
  270. },
  271. },
  272. {
  273. PosterName: "joubertredrat",
  274. Created: time.Date(2016, 11, 02, 19, 16, 56, 0, time.UTC),
  275. Content: `Yes, this plugin build on front-end, with backend I don't know too, but we can consider make component for this.
  276. In my case I use ajax to get data, but build on frontend anyway
  277. `,
  278. Reactions: &base.Reactions{
  279. TotalCount: 0,
  280. PlusOne: 0,
  281. MinusOne: 0,
  282. Laugh: 0,
  283. Confused: 0,
  284. Heart: 0,
  285. Hooray: 0,
  286. },
  287. },
  288. {
  289. PosterName: "xinity",
  290. Created: time.Date(2016, 11, 03, 13, 04, 56, 0, time.UTC),
  291. Content: `following @bkcsoft retention strategy in cache is a must if we don't want gitea to waste ressources.
  292. something like in the latest 15days could be enough don't you think ?
  293. `,
  294. Reactions: &base.Reactions{
  295. TotalCount: 2,
  296. PlusOne: 2,
  297. MinusOne: 0,
  298. Laugh: 0,
  299. Confused: 0,
  300. Heart: 0,
  301. Hooray: 0,
  302. },
  303. },
  304. }, comments[:3])
  305. // downloader.GetPullRequests()
  306. prs, err := downloader.GetPullRequests(1, 3)
  307. assert.NoError(t, err)
  308. assert.EqualValues(t, 3, len(prs))
  309. closed1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  310. var (
  311. closed2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  312. closed3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  313. )
  314. var (
  315. merged1 = time.Date(2016, 11, 02, 18, 22, 21, 0, time.UTC)
  316. merged2 = time.Date(2016, 11, 03, 8, 06, 27, 0, time.UTC)
  317. merged3 = time.Date(2016, 11, 02, 18, 22, 31, 0, time.UTC)
  318. )
  319. assert.EqualValues(t, []*base.PullRequest{
  320. {
  321. Number: 1,
  322. Title: "Rename import paths: \"github.com/gogits/gogs\" -> \"github.com/go-gitea/gitea\"",
  323. Content: "",
  324. Milestone: "1.0.0",
  325. PosterName: "andreynering",
  326. State: "closed",
  327. Created: time.Date(2016, 11, 02, 17, 01, 19, 0, time.UTC),
  328. Labels: []*base.Label{
  329. {
  330. Name: "kind/enhancement",
  331. Color: "84b6eb",
  332. },
  333. {
  334. Name: "lgtm/done",
  335. Color: "0e8a16",
  336. },
  337. },
  338. PatchURL: "https://github.com/go-gitea/gitea/pull/1.patch",
  339. Head: base.PullRequestBranch{
  340. Ref: "import-paths",
  341. SHA: "1b0ec3208db8501acba44a137c009a5a126ebaa9",
  342. OwnerName: "andreynering",
  343. },
  344. Base: base.PullRequestBranch{
  345. Ref: "master",
  346. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  347. OwnerName: "go-gitea",
  348. RepoName: "gitea",
  349. },
  350. Closed: &closed1,
  351. Merged: true,
  352. MergedTime: &merged1,
  353. MergeCommitSHA: "142d35e8d2baec230ddb565d1265940d59141fab",
  354. },
  355. {
  356. Number: 2,
  357. Title: "Fix sender of issue notifications",
  358. 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",
  359. Milestone: "1.0.0",
  360. PosterName: "strk",
  361. State: "closed",
  362. Created: time.Date(2016, 11, 02, 17, 24, 19, 0, time.UTC),
  363. Labels: []*base.Label{
  364. {
  365. Name: "kind/bug",
  366. Color: "ee0701",
  367. },
  368. {
  369. Name: "lgtm/done",
  370. Color: "0e8a16",
  371. },
  372. },
  373. PatchURL: "https://github.com/go-gitea/gitea/pull/2.patch",
  374. Head: base.PullRequestBranch{
  375. Ref: "proper-from-on-issue-mail",
  376. SHA: "af03d00780a6ee70c58e135c6679542cde4f8d50",
  377. RepoName: "gogs",
  378. OwnerName: "strk",
  379. CloneURL: "https://github.com/strk/gogs.git",
  380. },
  381. Base: base.PullRequestBranch{
  382. Ref: "develop",
  383. SHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  384. OwnerName: "go-gitea",
  385. RepoName: "gitea",
  386. },
  387. Closed: &closed2,
  388. Merged: true,
  389. MergedTime: &merged2,
  390. MergeCommitSHA: "d8de2beb5b92d02a0597ba7c7803839380666653",
  391. },
  392. {
  393. Number: 3,
  394. Title: "Use proper url for libravatar dep",
  395. Content: "Fetch go-libravatar from its official source, rather than from an unmaintained fork\r\n",
  396. Milestone: "1.0.0",
  397. PosterName: "strk",
  398. State: "closed",
  399. Created: time.Date(2016, 11, 02, 17, 34, 31, 0, time.UTC),
  400. Labels: []*base.Label{
  401. {
  402. Name: "kind/enhancement",
  403. Color: "84b6eb",
  404. },
  405. {
  406. Name: "lgtm/done",
  407. Color: "0e8a16",
  408. },
  409. },
  410. PatchURL: "https://github.com/go-gitea/gitea/pull/3.patch",
  411. Head: base.PullRequestBranch{
  412. Ref: "libravatar-proper-url",
  413. SHA: "d59a48a2550abd4129b96d38473941b895a4859b",
  414. RepoName: "gogs",
  415. OwnerName: "strk",
  416. CloneURL: "https://github.com/strk/gogs.git",
  417. },
  418. Base: base.PullRequestBranch{
  419. Ref: "develop",
  420. SHA: "6bcff7828f117af8d51285ce3acba01a7e40a867",
  421. OwnerName: "go-gitea",
  422. RepoName: "gitea",
  423. },
  424. Closed: &closed3,
  425. Merged: true,
  426. MergedTime: &merged3,
  427. MergeCommitSHA: "5c5424301443ffa3659737d12de48ab1dfe39a00",
  428. },
  429. }, prs)
  430. }