Skip to content

Release/v1.0.5 #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions __tests__/git-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ describe('GitHelper', () => {
await helper.checkout(workDir, context());

execCalledWith(mockExec, [
'rm -rdf \'.work\'',
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/heads/test-ref:refs/remotes/origin/test-ref\' || :',
'git checkout -qf test-sha',
Expand All @@ -124,8 +122,6 @@ describe('GitHelper', () => {
await helper.checkout(workDir, context({ref: 'refs/pull/123/merge'}));

execCalledWith(mockExec, [
'rm -rdf \'.work\'',
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/pull/123/merge:refs/pull/123/merge\' || :',
'git checkout -qf test-sha',
Expand All @@ -138,8 +134,6 @@ describe('GitHelper', () => {
await helper.checkout(workDir, context({ref: 'refs/tags/v1.2.3'}));

execCalledWith(mockExec, [
'rm -rdf \'.work\'',
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
'git checkout -qf test-sha',
Expand Down Expand Up @@ -179,6 +173,17 @@ describe('GitHelper', () => {

await helper.addOrigin(workDir, context());

execCalledWith(mockExec, [
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
]);
});

it('should run git init and git remote add', async() => {
const mockExec = spyOnExec();
setExists([false, true]);

await helper.addOrigin(workDir, context());

execCalledWith(mockExec, [
`rm -rdf '${workDir}'`,
'git init \'.\'',
Expand All @@ -194,8 +199,6 @@ describe('GitHelper', () => {
await helper.fetchOrigin(workDir, context());

execCalledWith(mockExec, [
`rm -rdf '${workDir}'`,
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch origin || :',
]);
Expand All @@ -207,8 +210,6 @@ describe('GitHelper', () => {
await helper.fetchOrigin(workDir, context(), ['--no-tags']);

execCalledWith(mockExec, [
`rm -rdf '${workDir}'`,
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin || :',
]);
Expand All @@ -220,8 +221,6 @@ describe('GitHelper', () => {
await helper.fetchOrigin(workDir, context(), undefined, ['+refs/pull/*/merge:refs/remotes/pull/*/merge', '+refs/heads/hoge:refs/remotes/origin/hoge']);

execCalledWith(mockExec, [
`rm -rdf '${workDir}'`,
'git init \'.\'',
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
'git fetch origin \'+refs/pull/*/merge:refs/remotes/pull/*/merge\' \'+refs/heads/hoge:refs/remotes/origin/hoge\' || :',
]);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-helper",
"version": "1.0.4",
"version": "1.0.5",
"description": "Helper to filter GitHub Action.",
"author": {
"name": "Technote",
Expand Down Expand Up @@ -40,7 +40,7 @@
"eslint": "^6.8.0",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"nock": "^11.7.2",
"nock": "^11.8.2",
"ts-jest": "^25.2.0",
"typescript": "^3.7.5"
},
Expand Down
9 changes: 7 additions & 2 deletions src/git-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ export default class GitHelper {

/**
* @param {string} workDir work dir
* @param {boolean} refresh refresh?
* @return {Promise<void>} void
*/
private initialize = async(workDir: string): Promise<void> => {
private initialize = async(workDir: string, refresh = true): Promise<void> => {
if (isCloned(workDir) && !refresh) {
return;
}

if (fs.existsSync(workDir)) {
await this.runCommand(workDir, {command: 'rm', args: ['-rdf', workDir]});
}
Expand All @@ -106,7 +111,7 @@ export default class GitHelper {
* @return {Promise<void>} void
*/
public addOrigin = async(workDir: string, context: Context): Promise<void> => {
await this.initialize(workDir);
await this.initialize(workDir, false);
await this.runCommand(workDir, {
command: 'git remote add',
args: ['origin', getGitUrlWithToken(context, this.token)],
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2833,10 +2833,10 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

nock@^11.7.2:
version "11.7.2"
resolved "https://registry.yarnpkg.com/nock/-/nock-11.7.2.tgz#4cee4fa838dc3635c074c5b3436bcdec7f7ee213"
integrity sha512-7swr5bL1xBZ5FctyubjxEVySXOSebyqcL7Vy1bx1nS9IUqQWj81cmKjVKJLr8fHhtzI1MV8nyCdENA/cGcY1+Q==
nock@^11.8.2:
version "11.8.2"
resolved "https://registry.yarnpkg.com/nock/-/nock-11.8.2.tgz#7845608d57769f41375b63521a7e6b554f4cdbb2"
integrity sha512-udrFXJ/aqPM9NmrKOcNJ67lvrs/zroNq2sbumhaMPW5JLNy/6LsWiZEwU9DiQIUHOcOCR4MPeqIG7uQNbDGExA==
dependencies:
debug "^4.1.0"
json-stringify-safe "^5.0.1"
Expand Down