Skip to content

Commit df5cd6b

Browse files
chore: tweaks
1 parent c3a32d9 commit df5cd6b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

__tests__/api-helper1.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const createCommitResponse: GitCreateCommitResponseData = {
5959
verified: true,
6060
},
6161
};
62-
const escape = value => encodeURIComponent(value).replace(new RegExp('%2F', 'g'), '%252F');
6362

6463
describe('ApiHelper', () => {
6564
disableNetConnect(nock);
@@ -213,7 +212,7 @@ describe('ApiHelper', () => {
213212
const fn1 = jest.fn();
214213
const fn2 = jest.fn();
215214
nock('https://api.github.com')
216-
.patch('/repos/hello/world/git/refs/' + escape('heads/test'), body => {
215+
.patch(`/repos/hello/world/git/refs/${encodeURIComponent('heads/test')}`, body => {
217216
fn1();
218217
expect(body).toHaveProperty('sha');
219218
return body;
@@ -223,7 +222,7 @@ describe('ApiHelper', () => {
223222
return getApiFixture(rootDir, 'repos.git.refs.update');
224223
});
225224

226-
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(true), false);
225+
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(false), false);
227226

228227
expect(fn1).toBeCalledTimes(1);
229228
expect(fn2).toBeCalledTimes(1);
@@ -234,7 +233,7 @@ describe('ApiHelper', () => {
234233
const fn2 = jest.fn();
235234
const fn3 = jest.fn();
236235
nock('https://api.github.com')
237-
.patch('/repos/hello/world/git/refs/' + escape('heads/new-topic'), body => {
236+
.patch(`/repos/hello/world/git/refs/${encodeURIComponent('heads/new-topic')}`, body => {
238237
fn1();
239238
expect(body).toHaveProperty('sha');
240239
return body;
@@ -253,7 +252,7 @@ describe('ApiHelper', () => {
253252
ref: 'refs/pull/123/merge',
254253
});
255254
const helper = new ApiHelper(octokit, _context, logger);
256-
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(true), false);
255+
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(false), false);
257256

258257
expect(fn1).toBeCalledTimes(1);
259258
expect(fn2).toBeCalledTimes(1);
@@ -263,7 +262,7 @@ describe('ApiHelper', () => {
263262
it('should cache PR get api', async() => {
264263
const fn = jest.fn();
265264
nock('https://api.github.com')
266-
.patch('/repos/hello/world/git/refs/' + escape('heads/new-topic'))
265+
.patch(`/repos/hello/world/git/refs/${encodeURIComponent('heads/new-topic')}`)
267266
.reply(200, () => {
268267
return getApiFixture(rootDir, 'repos.git.refs.update');
269268
})
@@ -279,22 +278,22 @@ describe('ApiHelper', () => {
279278
const helper = new ApiHelper(octokit, _context, logger);
280279
await helper.getRefForUpdate(true);
281280
await helper.getRefForUpdate(true);
282-
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(true), false);
281+
await helper.updateRef(createCommitResponse, await helper.getRefForUpdate(false), false);
283282

284283
expect(fn).toBeCalledTimes(1);
285284
});
286285

287286
it('should output warning', async() => {
288287
nock('https://api.github.com')
289-
.patch('/repos/hello/world/git/refs/' + escape('heads/test'), body => {
288+
.patch(`/repos/hello/world/git/refs/${encodeURIComponent('heads/test')}`, body => {
290289
expect(body).toHaveProperty('sha');
291290
return body;
292291
})
293292
.reply(403, {
294293
'message': 'Required status check "Test" is expected.',
295294
});
296295

297-
await expect(helper.updateRef(createCommitResponse, await helper.getRefForUpdate(true), false)).rejects.toThrow('Required status check "Test" is expected.');
296+
await expect(helper.updateRef(createCommitResponse, await helper.getRefForUpdate(false), false)).rejects.toThrow('Required status check "Test" is expected.');
298297
});
299298
});
300299

@@ -579,7 +578,7 @@ describe('ApiHelper', () => {
579578
.reply(201, () => getApiFixture(rootDir, 'repos.git.trees'))
580579
.post('/repos/hello/world/git/commits')
581580
.reply(201, () => getApiFixture(rootDir, 'repos.git.commits'))
582-
.patch('/repos/hello/world/git/refs/' + escape('heads/test'))
581+
.patch(`/repos/hello/world/git/refs/${encodeURIComponent('heads/test')}`)
583582
.reply(200, () => getApiFixture(rootDir, 'repos.git.refs.update'));
584583

585584
expect(await helper.commit(rootDir, 'test commit message', ['build1.json', 'build2.json'])).toBe(true);
@@ -590,7 +589,7 @@ describe('ApiHelper', () => {
590589
'::endgroup::',
591590
'::group::Creating commit... [cd8274d15fa3ae2ab983129fb037999f264ba9a7]',
592591
'::endgroup::',
593-
'::group::Updating ref... [heads%252Ftest] [7638417db6d59f3c431d3e1f261cc637155684cd]',
592+
'::group::Updating ref... [heads/test] [7638417db6d59f3c431d3e1f261cc637155684cd]',
594593
'::set-env name=GITHUB_SHA::7638417db6d59f3c431d3e1f261cc637155684cd',
595594
'::endgroup::',
596595
]);

src/api-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export default class ApiHelper {
444444
}
445445

446446
const commit = await this.prepareCommit(rootDir, commitMessage, files);
447-
const ref = await this.getRefForUpdate(true);
447+
const ref = await this.getRefForUpdate(false);
448448

449449
this.callLogger(logger => logger.startProcess('Updating ref... [%s] [%s]', ref, commit.sha));
450450
if (await this.updateRef(commit, ref, false)) {

0 commit comments

Comments
 (0)