| 1 | import { describe, expect, test } from "bun:test"; |
| 2 | |
| 3 | import type { GitHubIssue, |
| 4 | import { issueFrom, releaseFrom |
| 5 | |
| 6 | const issue: GitHubIssue |
| 7 | number: 7, |
| 8 | title: "Crash", |
| 9 | body: "It crashes", |
| 10 | user: { login: " |
| 11 | state: "closed", |
| 12 | labels: [{ name: |
| 13 | created_at: "2024-01-01T00:00:00Z", |
| 14 | updated_at: "2024-01-02T00:00:00Z", |
| 15 | closed_at: "2024-01-02T00:00:00Z", |
| 16 | }; |
| 17 | |
| 18 | const pull: GitHubPull |
| 19 | number: 7, |
| 20 | state: "closed", |
| 21 | draft: false, |
| 22 | merged_at: "2024-01-02T00:00:00Z", |
| 23 | merge_commit_sha: "a".repeat |
| 24 | base: { ref: " |
| 25 | head: { ref: " |
| 26 | }; |
| 27 | |
| 28 | const context = { |
| 29 | source: "octo/repo", |
| 30 | refs: new Set |
| 31 | present: new Set |
| 32 | }; |
| 33 | |
| 34 | describe("issueFrom", () |
| 35 | test("maps an issue, lowercasing label colours", |
| 36 | expect(issueFrom(issue |
| 37 | number: 7, |
| 38 | title: "Crash", |
| 39 | body: "It crashes", |
| 40 | authorLogin: "octocat", |
| 41 | state: "closed", |
| 42 | createdAt: "2024-01-01T00:00:00Z", |
| 43 | updatedAt: "2024-01-02T00:00:00Z", |
| 44 | closedAt: "2024-01-02T00:00:00Z", |
| 45 | labels: [{ name: |
| 46 | pullRequest: undefined, |
| 47 | }); |
| 48 | }); |
| 49 | |
| 50 | test("a merged pull request keeps its merge commit when the history has it", |
| 51 | expect(issueFrom(issue |
| 52 | state: "merged", |
| 53 | draft: false, |
| 54 | baseRef: "main", |
| 55 | headRef: "fix", |
| 56 | headSha: "b".repeat |
| 57 | headInRepository: true, |
| 58 | mergeCommitSha: "a".repeat |
| 59 | mergedAt: "2024-01-02T00:00:00Z", |
| 60 | }); |
| 61 | }); |
| 62 | |
| 63 | test("drops a merge commit the history lacks", |
| 64 | const result = |
| 65 | expect(result.pullRequest |
| 66 | }); |
| 67 | |
| 68 | test("a fork's branch, or a deleted one, is not in the repository", |
| 69 | const fork = |
| 70 | ...pull, |
| 71 | merged_at: null, |
| 72 | state: "open" as |
| 73 | head: { ...pull |
| 74 | }; |
| 75 | expect(issueFrom(issue |
| 76 | state: "open", |
| 77 | headInRepository: false, |
| 78 | mergeCommitSha: null, |
| 79 | }); |
| 80 | const gone = |
| 81 | expect(issueFrom(issue |
| 82 | false, |
| 83 | ); |
| 84 | expect( |
| 85 | issueFrom(issue, pull |
| 86 | ?.headInRepository, |
| 87 | ).toBe(false); |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | test("releaseFrom turns empty names and bodies into null", () |
| 92 | expect( |
| 93 | releaseFrom({ |
| 94 | tag_name: "v1", |
| 95 | name: "", |
| 96 | body: "", |
| 97 | draft: false, |
| 98 | prerelease: true, |
| 99 | created_at: "2024-01-01T00:00:00Z", |
| 100 | published_at: null, |
| 101 | }), |
| 102 | ).toEqual({ |
| 103 | tagName: "v1", |
| 104 | name: null, |
| 105 | body: null, |
| 106 | isDraft: false, |
| 107 | isPrerelease: true, |
| 108 | createdAt: "2024-01-01T00:00:00Z", |
| 109 | publishedAt: null, |
| 110 | }); |
| 111 | }); |