()
| 44 | } |
| 45 | |
| 46 | async function buildChangelog(): Promise<ChangelogVersion> { |
| 47 | const lastTag = last((await git.tags()).all); |
| 48 | if (!lastTag) throw new Error("Can't find tags"); |
| 49 | |
| 50 | const commits = await git.log({ from: lastTag, to: "HEAD" }); |
| 51 | |
| 52 | const authorsMap: { [hash: string]: string } = fromEntries( |
| 53 | await Promise.all( |
| 54 | commits.all.map((c) => |
| 55 | gh |
| 56 | .request("GET /repos/{owner}/{repo}/commits/{ref}", { |
| 57 | owner: "date-fns", |
| 58 | repo: "date-fns", |
| 59 | ref: c.hash, |
| 60 | }) |
| 61 | .then(({ data }) => [c.hash, data.author?.login] as [string, string]), |
| 62 | ), |
| 63 | ), |
| 64 | ); |
| 65 | |
| 66 | const items: ChangelogItem[] = []; |
| 67 | const authors: Author[] = []; |
| 68 | |
| 69 | commits.all.forEach((commit) => { |
| 70 | const author: Author = { |
| 71 | login: authorsMap[commit.hash], |
| 72 | email: commit.author_email, |
| 73 | name: commit.author_name, |
| 74 | }; |
| 75 | |
| 76 | const prCaptures = commit.message.match(/\(#(\d+)\)/); |
| 77 | const pr = prCaptures ? parseInt(prCaptures[1]) : undefined; |
| 78 | |
| 79 | let issues: number[] | undefined; |
| 80 | commit.message.match(new RegExp(closesRegExp, "g"))?.forEach((str) => { |
| 81 | const issueCaptures = str.match(closesRegExp); |
| 82 | if (issueCaptures) |
| 83 | issues = (issues || []).concat( |
| 84 | issueCaptures.slice(1).map((issue) => parseInt(issue)), |
| 85 | ); |
| 86 | }); |
| 87 | if (!issues?.length) issues = undefined; |
| 88 | |
| 89 | const commitItems = extractItems(commit.body.trim(), { |
| 90 | author, |
| 91 | pr, |
| 92 | issues, |
| 93 | }); |
| 94 | |
| 95 | if (!authors.find((a) => a.login === author.login)) authors.push(author); |
| 96 | items.push(...commitItems); |
| 97 | }); |
| 98 | |
| 99 | const changed = items.filter((i) => i.type === "changed"); |
| 100 | const fixed = items.filter((i) => i.type === "fixed"); |
| 101 | const added = items.filter((i) => i.type === "added"); |
| 102 | |
| 103 | const lastVersion = parseVersion(lastTag); |
no test coverage detected