Skip to content

Commit aaae739

Browse files
Merge pull request #302 from technote-space/release/next-v3.3.1
release: v3.4.0
2 parents 7a8bdab + 447dad7 commit aaae739

File tree

4 files changed

+508
-342
lines changed

4 files changed

+508
-342
lines changed

__tests__/git-helper.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,45 @@ describe('GitHelper', () => {
576576
});
577577
});
578578

579+
describe('deleteLocalTag', () => {
580+
it('should delete tag', async() => {
581+
const mockExec = spyOnSpawn();
582+
583+
await helper.deleteLocalTag(workDir, 'delete-tag');
584+
585+
execCalledWith(mockExec, [
586+
'git tag -d delete-tag || :',
587+
]);
588+
});
589+
590+
it('should run add tags', async() => {
591+
const mockExec = spyOnSpawn();
592+
593+
await helper.deleteLocalTag(workDir, ['delete-tag1', 'delete-tag2']);
594+
595+
execCalledWith(mockExec, [
596+
'git tag -d delete-tag1 delete-tag2 || :',
597+
]);
598+
});
599+
600+
it('should chunk delete tags', async() => {
601+
const mockExec = spyOnSpawn();
602+
603+
await helper.deleteLocalTag(workDir, [
604+
'delete-tag1',
605+
'delete-tag2',
606+
'delete-tag3',
607+
'tags/delete-tag4',
608+
'refs/tags/delete-tag5',
609+
], 3);
610+
611+
execCalledWith(mockExec, [
612+
'git tag -d delete-tag1 delete-tag2 delete-tag3 || :',
613+
'git tag -d delete-tag4 delete-tag5 || :',
614+
]);
615+
});
616+
});
617+
579618
describe('addLocalTag', () => {
580619
it('should run add tag', async() => {
581620
const mockExec = spyOnSpawn();

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "3.3.1",
3+
"version": "3.4.0",
44
"description": "Helper for GitHub Action.",
55
"author": {
66
"name": "Technote",
@@ -26,28 +26,28 @@
2626
"dist"
2727
],
2828
"dependencies": {
29-
"@actions/core": "^1.2.4",
29+
"@actions/core": "^1.2.5",
3030
"@actions/github": "^4.0.0",
31-
"@octokit/plugin-rest-endpoint-methods": "^4.1.2",
31+
"@octokit/plugin-rest-endpoint-methods": "^4.1.3",
3232
"shell-escape": "^0.2.0",
3333
"sprintf-js": "^1.1.2"
3434
},
3535
"devDependencies": {
3636
"@commitlint/cli": "^9.1.2",
3737
"@commitlint/config-conventional": "^9.1.2",
3838
"@technote-space/github-action-test-helper": "^0.5.6",
39-
"@types/jest": "^26.0.10",
40-
"@types/node": "^14.6.0",
41-
"@typescript-eslint/eslint-plugin": "^3.9.1",
42-
"@typescript-eslint/parser": "^3.9.1",
43-
"eslint": "^7.7.0",
39+
"@types/jest": "^26.0.12",
40+
"@types/node": "^14.6.2",
41+
"@typescript-eslint/eslint-plugin": "^4.0.1",
42+
"@typescript-eslint/parser": "^4.0.1",
43+
"eslint": "^7.8.0",
4444
"husky": "^4.2.5",
45-
"jest": "^26.4.0",
46-
"jest-circus": "^26.4.0",
47-
"lint-staged": "^10.2.11",
45+
"jest": "^26.4.2",
46+
"jest-circus": "^26.4.2",
47+
"lint-staged": "^10.2.13",
4848
"nock": "^13.0.4",
49-
"ts-jest": "^26.2.0",
50-
"typescript": "^3.9.7"
49+
"ts-jest": "^26.3.0",
50+
"typescript": "^4.0.2"
5151
},
5252
"publishConfig": {
5353
"access": "public"

src/git-helper.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,24 +457,17 @@ export default class GitHelper {
457457
* @return {Promise<void>} void
458458
*/
459459
public deleteTag = async(workDir: string, tags: string | string[], context: Context, splitSize = 20): Promise<void> => { // eslint-disable-line no-magic-numbers
460-
const regexp = /^(refs\/)?tags\//;
461-
const getTagRef = (tag: string): string => regexp.test(tag) ? tag : `tags/${tag}`;
462-
const getTag = (tag: string): string => tag.replace(regexp, '');
463-
await this.runCommand(workDir, [
464-
...arrayChunk((typeof tags === 'string' ? [tags] : tags).map(getTagRef), splitSize).map(tags => ({
460+
const getTagRef = (tag: string): string => /^(refs\/)?tags\//.test(tag) ? tag : `tags/${tag}`;
461+
await this.runCommand(workDir,
462+
arrayChunk((typeof tags === 'string' ? [tags] : tags).map(getTagRef), splitSize).map(tags => ({
465463
command: 'git push',
466464
args: [this.getRemote(context), '--delete', ...tags],
467465
quiet: this.isQuiet(),
468466
altCommand: `git push ${this.getRemoteName()} --delete ${tags.join(' ')}`,
469467
suppressError: true,
470468
})),
471-
...arrayChunk((typeof tags === 'string' ? [tags] : tags).map(getTag), splitSize).map(tags => ({
472-
command: 'git tag',
473-
args: ['-d', ...tags],
474-
suppressError: true,
475-
stderrToStdout: true,
476-
})),
477-
]);
469+
);
470+
await this.deleteLocalTag(workDir, tags, splitSize);
478471
};
479472

480473
/**
@@ -500,6 +493,24 @@ export default class GitHelper {
500493
]);
501494
};
502495

496+
/**
497+
* @param {string} workDir work dir
498+
* @param {string|string[]} tags tags
499+
* @param {number} splitSize split size
500+
* @return {Promise<void>} void
501+
*/
502+
public deleteLocalTag = async(workDir: string, tags: string | string[], splitSize = 20): Promise<void> => { // eslint-disable-line no-magic-numbers
503+
const getTag = (tag: string): string => tag.replace(/^(refs\/)?tags\//, '');
504+
await this.runCommand(workDir, arrayChunk((typeof tags === 'string' ? [tags] : tags).map(getTag), splitSize).map(
505+
tags => ({
506+
command: 'git tag',
507+
args: ['-d', ...tags],
508+
suppressError: true,
509+
stderrToStdout: true,
510+
}),
511+
));
512+
};
513+
503514
/**
504515
* @param {string} workDir work dir
505516
* @param {string|string[]} tags tags

0 commit comments

Comments
 (0)