Skip to content

Commit 8f7c9d0

Browse files
authored
Revert "use github api to find pull request for commit"
1 parent 506304a commit 8f7c9d0

21 files changed

+681
-803
lines changed

package.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"clean": "rimraf lib",
2727
"fix": "pnpm lint --fix",
2828
"lint": "eslint src --ext ts --format stylish",
29-
"lint:types": "tsc --noEmit",
30-
"prepare": "pnpm build",
29+
"prepack": "pnpm build",
3130
"prettier": "prettier --write 'src/**/*.ts'",
3231
"test": "vitest",
3332
"test-ci": "pnpm build && pnpm test",
@@ -42,7 +41,6 @@
4241
},
4342
"dependencies": {
4443
"@manypkg/get-packages": "^2.2.0",
45-
"@octokit/rest": "^21.1.0",
4644
"chalk": "^4.0.0",
4745
"cli-highlight": "^2.1.11",
4846
"execa": "^5.0.0",
@@ -53,10 +51,7 @@
5351
"yargs": "^17.1.0"
5452
},
5553
"devDependencies": {
56-
"@types/fs-extra": "^11.0.4",
57-
"@types/hosted-git-info": "^3.0.5",
5854
"@types/node": "22.10.10",
59-
"@types/yargs": "^17.0.33",
6055
"@typescript-eslint/eslint-plugin": "5.62.0",
6156
"@typescript-eslint/parser": "5.62.0",
6257
"eslint": "8.55.0",
@@ -67,7 +62,7 @@
6762
"release-plan": "^0.11.0",
6863
"rimraf": "3.0.2",
6964
"typescript": "5.0.4",
70-
"vitest": "^3.0.7"
65+
"vitest": "^3.0.4"
7166
},
7267
"packageManager": "pnpm@10.4.1+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af",
7368
"engines": {

pnpm-lock.yaml

+221-359
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__mocks__/@octokit/rest.ts

-31
This file was deleted.

src/__snapshots__/changelog.spec.js.snap

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
exports[`Changelog > getCommitInfos > parse commits with different tags 1`] = `
44
[
5-
{
6-
"commitSHA": "a0000006",
7-
"date": "2017-01-01",
8-
"issueNumber": null,
9-
"message": "Merge pull request #3 from my-feature-3",
10-
"packages": [],
11-
"tags": undefined,
12-
},
135
{
146
"commitSHA": "a0000005",
157
"date": "2017-01-01",
@@ -64,7 +56,7 @@ exports[`Changelog > getCommitInfos > parse commits with different tags 1`] = `
6456
},
6557
],
6658
"number": 2,
67-
"title": "feat(module) Add new module (#2)",
59+
"title": "This is the commit title for the issue (#2)",
6860
"user": {
6961
"html_url": "https://github.com/test-user",
7062
"login": "test-user",

src/changelog.spec.js

+40-52
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest";
2-
import * as MockedOctokit from "./__mocks__/@octokit/rest";
3-
import { Octokit } from "@octokit/rest";
2+
43
import Changelog from "./changelog";
4+
import * as fetch from "./fetch";
55
import * as git from "./git";
66

7-
vi.mock("@octokit/rest");
87
vi.mock("../src/progress-bar");
98
vi.mock("../src/changelog");
109
vi.mock("../src/github-api");
1110
vi.mock("./git");
11+
vi.mock("./fetch");
1212

1313
describe("Changelog", () => {
14-
beforeEach(() => {
15-
Octokit.mockImplementation((...args) => MockedOctokit.Octokit(...args));
16-
});
17-
afterEach(() => {
18-
vi.resetAllMocks();
19-
});
2014
describe("packageFromPath", () => {
2115
const TESTS = [
2216
["", ""],
@@ -95,7 +89,7 @@ describe("Changelog", () => {
9589

9690
describe("getCommitInfos", () => {
9791
beforeEach(() => {
98-
MockedOctokit.__resetMockResponses();
92+
fetch.__resetMockResponses();
9993

10094
git.listCommits.mockImplementation(() => [
10195
{
@@ -141,47 +135,35 @@ describe("Changelog", () => {
141135
git.changedPaths.mockImplementation(() => []);
142136

143137
const usersCache = {
144-
"test-user": {
138+
"https://api.github.com/users/test-user": {
145139
body: {
146140
login: "test-user",
147141
html_url: "https://github.com/test-user",
148142
name: "Test User",
149143
},
150144
},
151145
};
152-
const prCache = {
153-
a0000001: [],
154-
a0000002: [],
155-
a0000003: [
156-
{
157-
number: 2,
158-
title: "feat(module) Add new module (#2)",
159-
labels: [{ name: "Type: New Feature" }, { name: "Status: In Progress" }],
160-
user: usersCache["test-user"].body,
161-
},
162-
],
163-
a0000004: [
164-
{
146+
const issuesCache = {
147+
"https://api.github.com/repos/embroider-build/github-changelog/issues/2": {
148+
body: {
165149
number: 2,
166150
title: "This is the commit title for the issue (#2)",
167151
labels: [{ name: "Type: New Feature" }, { name: "Status: In Progress" }],
168-
user: usersCache["test-user"].body,
152+
user: usersCache["https://api.github.com/users/test-user"].body,
169153
},
170-
],
171-
a0000005: [],
172-
a0000006: [],
154+
},
173155
"https://api.github.com/repos/embroider-build/github-changelog/issues/3": {
174156
body: {
175157
number: 2,
176158
title: "This is the commit title for the issue (#2)",
177159
labels: [{ name: "ignore" }, { name: "Status: In Progress" }],
178-
user: usersCache["test-user"].body,
160+
user: usersCache["https://api.github.com/users/test-user"].body,
179161
},
180162
},
181163
};
182-
MockedOctokit.__setMockResponses({
183-
users: { ...usersCache },
184-
prs: { ...prCache },
164+
fetch.__setMockResponses({
165+
...usersCache,
166+
...issuesCache,
185167
});
186168
});
187169

@@ -199,33 +181,39 @@ describe("Changelog", () => {
199181

200182
describe("getCommitters", () => {
201183
beforeEach(() => {
202-
MockedOctokit.__resetMockResponses();
184+
fetch.__resetMockResponses();
203185

204186
const usersCache = {
205-
"test-user": {
206-
login: "test-user",
207-
html_url: "https://github.com/test-user",
208-
name: "Test User",
187+
"https://api.github.com/users/test-user": {
188+
body: {
189+
login: "test-user",
190+
html_url: "https://github.com/test-user",
191+
name: "Test User",
192+
},
209193
},
210-
"test-user-1": {
211-
login: "test-user-1",
212-
html_url: "https://github.com/test-user-1",
213-
name: "Test User 1",
194+
"https://api.github.com/users/test-user-1": {
195+
body: {
196+
login: "test-user-1",
197+
html_url: "https://github.com/test-user-1",
198+
name: "Test User 1",
199+
},
214200
},
215-
"test-user-2": {
216-
login: "test-user-2",
217-
html_url: "https://github.com/test-user-2",
218-
name: "Test User 2",
201+
"https://api.github.com/users/test-user-2": {
202+
body: {
203+
login: "test-user-2",
204+
html_url: "https://github.com/test-user-2",
205+
name: "Test User 2",
206+
},
219207
},
220-
"user-bot": {
221-
login: "user-bot",
222-
html_url: "https://github.com/user-bot",
223-
name: "User Bot",
208+
"https://api.github.com/users/user-bot": {
209+
body: {
210+
login: "user-bot",
211+
html_url: "https://github.com/user-bot",
212+
name: "User Bot",
213+
},
224214
},
225215
};
226-
MockedOctokit.__setMockResponses({
227-
users: { ...usersCache },
228-
});
216+
fetch.__setMockResponses(usersCache);
229217
});
230218

231219
it("get list of valid commiters", async () => {

src/changelog.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import pMap from "p-map";
1+
const pMap = require("p-map");
2+
const { resolve, sep } = require("path");
3+
24
import progressBar from "./progress-bar";
35
import { Configuration } from "./configuration";
6+
import findPullRequestId from "./find-pull-request-id";
47
import * as Git from "./git";
58
import GithubAPI, { GitHubUserResponse } from "./github-api";
69
import { CommitInfo, Release } from "./interfaces";
710
import MarkdownRenderer from "./markdown-renderer";
811

9-
import { resolve, sep } from "path";
10-
1112
const UNRELEASED_TAG = "___unreleased___";
1213

1314
interface Options {
@@ -65,7 +66,7 @@ export default class Changelog {
6566
const commits = await this.getCommitInfos(from, to);
6667

6768
// Step 6: Group commits by release (local)
68-
const releases = this.groupByRelease(commits);
69+
let releases = this.groupByRelease(commits);
6970

7071
// Step 7: Compile list of committers in release (local + remote)
7172
await this.fillInContributors(releases);
@@ -74,7 +75,8 @@ export default class Changelog {
7475
}
7576

7677
private async getListOfUniquePackages(sha: string): Promise<string[]> {
77-
const changedPaths = await Git.changedPaths(sha);
78+
let changedPaths = await Git.changedPaths(sha);
79+
7880
return changedPaths
7981
.map(path => this.packageFromPath(path))
8082
.filter(Boolean)
@@ -90,7 +92,7 @@ export default class Changelog {
9092
// ember-fastboot
9193
// ember-fastboot-2-fast-2-furious
9294
const foundPackage = this.config.packages.find(p => {
93-
const withSlash = p.path.endsWith(sep) ? p.path : `${p.path}${sep}`;
95+
let withSlash = p.path.endsWith(sep) ? p.path : `${p.path}${sep}`;
9496

9597
return absolutePath.startsWith(withSlash);
9698
});
@@ -128,7 +130,7 @@ export default class Changelog {
128130
for (const commit of commits) {
129131
const issue = commit.githubIssue;
130132
const login = issue && issue.user && issue.user.login;
131-
// If a list of `ignoreCommitters` is provided in the lernaon config
133+
// If a list of `ignoreCommitters` is provided in the lerna.json config
132134
// check if the current committer should be kept or not.
133135
const shouldKeepCommiter = login && !this.ignoreCommitter(login);
134136
if (login && shouldKeepCommiter && !committers[login]) {
@@ -159,13 +161,15 @@ export default class Changelog {
159161
.map(ref => ref.substr(TAG_PREFIX.length));
160162
}
161163

164+
const issueNumber = findPullRequestId(message);
165+
162166
return {
163167
commitSHA: sha,
164168
message,
165169
// Note: Only merge commits or commits referencing an issue / PR
166170
// will be kept in the changelog.
167171
tags: tagsInCommit,
168-
issueNumber: null,
172+
issueNumber,
169173
date,
170174
} as CommitInfo;
171175
});
@@ -176,11 +180,8 @@ export default class Changelog {
176180
await pMap(
177181
commitInfos,
178182
async (commitInfo: CommitInfo) => {
179-
const issueData = await this.github.getPullRequest(this.config.repo, commitInfo.commitSHA);
180-
181-
if (issueData) {
182-
commitInfo.issueNumber = issueData.number.toString();
183-
commitInfo.githubIssue = issueData;
183+
if (commitInfo.issueNumber) {
184+
commitInfo.githubIssue = await this.github.getIssueData(this.config.repo, commitInfo.issueNumber);
184185
}
185186

186187
progressBar.tick();
@@ -194,7 +195,7 @@ export default class Changelog {
194195
// Analyze the commits and group them by tag.
195196
// This is useful to generate multiple release logs in case there are
196197
// multiple release tags.
197-
const releaseMap: { [id: string]: Release } = {};
198+
let releaseMap: { [id: string]: Release } = {};
198199

199200
let currentTags = [UNRELEASED_TAG];
200201
for (const commit of commits) {
@@ -209,11 +210,11 @@ export default class Changelog {
209210
// referencing them.
210211
for (const currentTag of currentTags) {
211212
if (!releaseMap[currentTag]) {
212-
const date = currentTag === UNRELEASED_TAG ? this.getToday() : commit.date;
213+
let date = currentTag === UNRELEASED_TAG ? this.getToday() : commit.date;
213214
releaseMap[currentTag] = { name: currentTag, date, commits: [] };
214215
}
215216

216-
const prUserLogin = commit.githubIssue?.user?.login;
217+
let prUserLogin = commit.githubIssue?.user.login;
217218
if (prUserLogin && !this.ignoreCommitter(prUserLogin)) {
218219
releaseMap[currentTag].commits.push(commit);
219220
}
@@ -235,10 +236,10 @@ export default class Changelog {
235236
const labels = commit.githubIssue.labels.map(label => label.name.toLowerCase());
236237

237238
if (this.config.wildcardLabel) {
238-
// check whether the commit has any of the labels from the learnaon config.
239+
// check whether the commit has any of the labels from the learna.json config.
239240
// If not, label this commit with the provided label
240241

241-
const foundLabel = Object.keys(this.config.labels).some(label => labels.indexOf(label.toLowerCase()) !== -1);
242+
let foundLabel = Object.keys(this.config.labels).some(label => labels.indexOf(label.toLowerCase()) !== -1);
242243

243244
if (!foundLabel) {
244245
labels.push(this.config.wildcardLabel);

0 commit comments

Comments
 (0)