Skip to content

Commit 96e7a22

Browse files
j-emmelaxel-op
authored andcommitted
Get 100 latest formatter releases
By default, Github's API returns 30 results per page for 'list' requests; this cuts off old Google Java Format releases, including any that run on Java 8. 100 is the maxmimum. There are 42 releases at time of writing, so this happens to let them all through.
1 parent c255004 commit 96e7a22

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

__tests__/releases.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function mockOctokitReturnRelease(releaseData: ReleaseData) {
105105
}
106106

107107
const URL_BASE = "https://api.github.com/repos/google/google-java-format/releases";
108+
const URL_TAIL = "?per_page=100";
108109

109110
describe('get all release data', () => {
110111
test('get all release data with API', async () => {
@@ -113,7 +114,7 @@ describe('get all release data', () => {
113114
const results = await releases.getAllReleaseData();
114115
expect(results).toEqual(allReleases);
115116
// IMPORTANT: should not have a trailing slash
116-
expectLastCurlCallForUrl(URL_BASE);
117+
expectLastCurlCallForUrl(URL_BASE + URL_TAIL);
117118
});
118119

119120
test('get all release data with API and call to API fails', async () => {
@@ -124,7 +125,7 @@ describe('get all release data', () => {
124125
.rejects
125126
.toThrow(error)
126127
// IMPORTANT: should not have a trailing slash
127-
expectLastCurlCallForUrl(URL_BASE);
128+
expectLastCurlCallForUrl(URL_BASE + URL_TAIL);
128129
});
129130

130131
test('get all release data with octokit', async () => {
@@ -148,14 +149,14 @@ describe('get latest release data', () => {
148149
const result = await releases.getLatestReleaseData(javaVersion);
149150
expect(result).toEqual(expectedRelease);
150151
// IMPORTANT: should not have a trailing slash
151-
expectLastCurlCallForUrl(URL_BASE);
152+
expectLastCurlCallForUrl(URL_BASE + URL_TAIL);
152153
});
153154

154155
test('when java version is 21, then return release latest', async () => {
155156
mockApiReturnRelease(dummyReleaseData);
156157
const result = await releases.getLatestReleaseData(21);
157158
expect(result).toEqual(dummyReleaseData);
158-
expectLastCurlCallForUrl(URL_BASE + "/latest");
159+
expectLastCurlCallForUrl(URL_BASE + "/latest" + URL_TAIL);
159160
});
160161
});
161162

@@ -166,7 +167,7 @@ describe('get latest release data', () => {
166167
expect(() => releases.getLatestReleaseData(21))
167168
.rejects
168169
.toThrow(error);
169-
expectLastCurlCallForUrl(URL_BASE + "/latest");
170+
expectLastCurlCallForUrl(URL_BASE + "/latest" + URL_TAIL);
170171
});
171172

172173
describe('get latest release data with octokit', () => {
@@ -195,7 +196,7 @@ describe('get release by name', () => {
195196
const result = await releases.getReleaseDataByName('dummy-release-data');
196197
expect(result).toEqual(dummyReleaseData);
197198
// IMPORTANT: should not have a trailing slash
198-
expectLastCurlCallForUrl(URL_BASE);
199+
expectLastCurlCallForUrl(URL_BASE + URL_TAIL);
199200
});
200201

201202
test('get release by name (non-existing)', async () => {
@@ -204,6 +205,6 @@ describe('get release by name', () => {
204205
const result = await releases.getReleaseDataByName('non-existing-data');
205206
expect(result).toBeUndefined();
206207
// IMPORTANT: should not have a trailing slash
207-
expectLastCurlCallForUrl(URL_BASE);
208+
expectLastCurlCallForUrl(URL_BASE + URL_TAIL);
208209
});
209210
});

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32713,15 +32713,15 @@ class Releases {
3271332713
this.octokit = octokit;
3271432714
}
3271532715
async callReleasesApi(pathParameter) {
32716-
const url = `${Releases.apiReleases}${pathParameter || ''}`;
32716+
const url = `${Releases.apiReleases}${pathParameter || ''}?per_page=100`;
3271732717
const response = await this.execute('curl', ['-sL', url], { ignoreReturnCode: false });
3271832718
return JSON.parse(response.stdOut);
3271932719
}
3272032720
async getAllReleaseData() {
3272132721
if (!this.octokit) {
3272232722
return this.callReleasesApi();
3272332723
}
32724-
const params = { owner: const_1.repositoryOwner, repo: const_1.repositoryName };
32724+
const params = { owner: const_1.repositoryOwner, repo: const_1.repositoryName, per_page: 100 };
3272532725
const response = await this.octokit.rest.repos.listReleases(params);
3272632726
return response.data;
3272732727
}

src/releases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Releases {
2121
private async callReleasesApi(pathParameter: string | number): Promise<ReleaseData>;
2222
private async callReleasesApi(pathParameter?: number): Promise<ReleaseData | ReleaseData[]>;
2323
private async callReleasesApi(pathParameter?: string | number): Promise<ReleaseData | ReleaseData[]> {
24-
const url = `${Releases.apiReleases}${pathParameter || ''}`;
24+
const url = `${Releases.apiReleases}${pathParameter || ''}?per_page=100`;
2525
const response = await this.execute('curl', ['-sL', url], { ignoreReturnCode: false });
2626
return JSON.parse(response.stdOut);
2727
}
@@ -30,7 +30,7 @@ export class Releases {
3030
if (!this.octokit) {
3131
return this.callReleasesApi();
3232
}
33-
const params = { owner: GJF_REPO_OWNER, repo: GJF_REPO_NAME };
33+
const params = { owner: GJF_REPO_OWNER, repo: GJF_REPO_NAME, per_page: 100 };
3434
const response = await this.octokit.rest.repos.listReleases(params);
3535
return response.data;
3636
}

0 commit comments

Comments
 (0)