Skip to content

Commit 3e002a4

Browse files
authored
Addressing code review comments for PR #922
1 parent 092f9bd commit 3e002a4

File tree

5 files changed

+77
-66
lines changed

5 files changed

+77
-66
lines changed

__test__/git-auth-helper.test.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as io from '@actions/io'
55
import * as os from 'os'
66
import * as path from 'path'
77
import * as stateHelper from '../lib/state-helper'
8-
import { IGitCommandManager } from '../lib/git-command-manager'
9-
import { IGitSourceSettings } from '../lib/git-source-settings'
8+
import {IGitCommandManager} from '../lib/git-command-manager'
9+
import {IGitSourceSettings} from '../lib/git-source-settings'
1010

1111
const isWindows = process.platform === 'win32'
1212
const testWorkspace = path.join(__dirname, '_temp', 'git-auth-helper')
@@ -17,7 +17,7 @@ let localGitConfigPath: string
1717
let globalGitConfigPath: string
1818
let runnerTemp: string
1919
let tempHomedir: string
20-
let git: IGitCommandManager & { env: { [key: string]: string } }
20+
let git: IGitCommandManager & {env: {[key: string]: string}}
2121
let settings: IGitSourceSettings
2222
let sshPath: string
2323
let githubServerUrl: string
@@ -33,7 +33,7 @@ describe('git-auth-helper tests', () => {
3333

3434
beforeEach(() => {
3535
// Mock setSecret
36-
jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => { })
36+
jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => {})
3737

3838
// Mock error/warning/info/debug
3939
jest.spyOn(core, 'error').mockImplementation(jest.fn())
@@ -68,7 +68,10 @@ describe('git-auth-helper tests', () => {
6868
}
6969
})
7070

71-
async function testAuthHeader(testName: string, serverUrl: string | undefined = undefined) {
71+
async function testAuthHeader(
72+
testName: string,
73+
serverUrl: string | undefined = undefined
74+
) {
7275
// Arrange
7376
let expectedServerUrl = 'https://github.com'
7477
if (serverUrl) {
@@ -101,17 +104,25 @@ describe('git-auth-helper tests', () => {
101104
const configureAuth_configuresAuthHeader =
102105
'configureAuth configures auth header'
103106
it(configureAuth_configuresAuthHeader, async () => {
104-
await testAuthHeader(configureAuth_configuresAuthHeader);
107+
await testAuthHeader(configureAuth_configuresAuthHeader)
105108
})
106109

107-
const configureAuth_AcceptsGitHubServerUrl = 'inject https://my-ghes-server.com as github server url'
110+
const configureAuth_AcceptsGitHubServerUrl =
111+
'inject https://my-ghes-server.com as github server url'
108112
it(configureAuth_AcceptsGitHubServerUrl, async () => {
109-
await testAuthHeader(configureAuth_AcceptsGitHubServerUrl, 'https://my-ghes-server.com');
113+
await testAuthHeader(
114+
configureAuth_AcceptsGitHubServerUrl,
115+
'https://my-ghes-server.com'
116+
)
110117
})
111118

112-
const configureAuth_AcceptsGitHubServerUrlSetToGHEC = 'inject https://github.com as github server url'
119+
const configureAuth_AcceptsGitHubServerUrlSetToGHEC =
120+
'inject https://github.com as github server url'
113121
it(configureAuth_AcceptsGitHubServerUrlSetToGHEC, async () => {
114-
await testAuthHeader(configureAuth_AcceptsGitHubServerUrl, 'https://github.com');
122+
await testAuthHeader(
123+
configureAuth_AcceptsGitHubServerUrl,
124+
'https://github.com'
125+
)
115126
})
116127

117128
const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
@@ -699,17 +710,17 @@ async function setup(testName: string): Promise<void> {
699710
workspace = path.join(testWorkspace, testName, 'workspace')
700711
runnerTemp = path.join(testWorkspace, testName, 'runner-temp')
701712
tempHomedir = path.join(testWorkspace, testName, 'home-dir')
702-
await fs.promises.mkdir(workspace, { recursive: true })
703-
await fs.promises.mkdir(runnerTemp, { recursive: true })
704-
await fs.promises.mkdir(tempHomedir, { recursive: true })
713+
await fs.promises.mkdir(workspace, {recursive: true})
714+
await fs.promises.mkdir(runnerTemp, {recursive: true})
715+
await fs.promises.mkdir(tempHomedir, {recursive: true})
705716
process.env['RUNNER_TEMP'] = runnerTemp
706717
process.env['HOME'] = tempHomedir
707718

708719
// Create git config
709720
globalGitConfigPath = path.join(tempHomedir, '.gitconfig')
710721
await fs.promises.writeFile(globalGitConfigPath, '')
711722
localGitConfigPath = path.join(workspace, '.git', 'config')
712-
await fs.promises.mkdir(path.dirname(localGitConfigPath), { recursive: true })
723+
await fs.promises.mkdir(path.dirname(localGitConfigPath), {recursive: true})
713724
await fs.promises.writeFile(localGitConfigPath, '')
714725

715726
git = {

dist/index.js

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,51 +1295,6 @@ module.exports._parse = parse;
12951295
module.exports._enoent = enoent;
12961296

12971297

1298-
/***/ }),
1299-
1300-
/***/ 24:
1301-
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1302-
1303-
"use strict";
1304-
1305-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1306-
if (k2 === undefined) k2 = k;
1307-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1308-
}) : (function(o, m, k, k2) {
1309-
if (k2 === undefined) k2 = k;
1310-
o[k2] = m[k];
1311-
}));
1312-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
1313-
Object.defineProperty(o, "default", { enumerable: true, value: v });
1314-
}) : function(o, v) {
1315-
o["default"] = v;
1316-
});
1317-
var __importStar = (this && this.__importStar) || function (mod) {
1318-
if (mod && mod.__esModule) return mod;
1319-
var result = {};
1320-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1321-
__setModuleDefault(result, mod);
1322-
return result;
1323-
};
1324-
Object.defineProperty(exports, "__esModule", { value: true });
1325-
exports.getOctokit = exports.Octokit = void 0;
1326-
const github = __importStar(__webpack_require__(469));
1327-
const url_helper_1 = __webpack_require__(81);
1328-
// Centralize all Octokit references by re-exporting
1329-
var rest_1 = __webpack_require__(0);
1330-
Object.defineProperty(exports, "Octokit", { enumerable: true, get: function () { return rest_1.Octokit; } });
1331-
function getOctokit(authToken, opts) {
1332-
const options = {
1333-
baseUrl: (0, url_helper_1.getServerApiUrl)(opts.baseUrl)
1334-
};
1335-
if (opts.userAgent) {
1336-
options.userAgent = opts.userAgent;
1337-
}
1338-
return new github.GitHub(authToken, options);
1339-
}
1340-
exports.getOctokit = getOctokit;
1341-
1342-
13431298
/***/ }),
13441299

13451300
/***/ 26:
@@ -4125,6 +4080,51 @@ function authenticationPlugin(octokit, options) {
41254080
}
41264081

41274082

4083+
/***/ }),
4084+
4085+
/***/ 195:
4086+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
4087+
4088+
"use strict";
4089+
4090+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4091+
if (k2 === undefined) k2 = k;
4092+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4093+
}) : (function(o, m, k, k2) {
4094+
if (k2 === undefined) k2 = k;
4095+
o[k2] = m[k];
4096+
}));
4097+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
4098+
Object.defineProperty(o, "default", { enumerable: true, value: v });
4099+
}) : function(o, v) {
4100+
o["default"] = v;
4101+
});
4102+
var __importStar = (this && this.__importStar) || function (mod) {
4103+
if (mod && mod.__esModule) return mod;
4104+
var result = {};
4105+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
4106+
__setModuleDefault(result, mod);
4107+
return result;
4108+
};
4109+
Object.defineProperty(exports, "__esModule", { value: true });
4110+
exports.getOctokit = exports.Octokit = void 0;
4111+
const github = __importStar(__webpack_require__(469));
4112+
const url_helper_1 = __webpack_require__(81);
4113+
// Centralize all Octokit references by re-exporting
4114+
var rest_1 = __webpack_require__(0);
4115+
Object.defineProperty(exports, "Octokit", { enumerable: true, get: function () { return rest_1.Octokit; } });
4116+
function getOctokit(authToken, opts) {
4117+
const options = {
4118+
baseUrl: (0, url_helper_1.getServerApiUrl)(opts.baseUrl)
4119+
};
4120+
if (opts.userAgent) {
4121+
options.userAgent = opts.userAgent;
4122+
}
4123+
return new github.GitHub(authToken, options);
4124+
}
4125+
exports.getOctokit = getOctokit;
4126+
4127+
41284128
/***/ }),
41294129

41304130
/***/ 197:
@@ -4340,7 +4340,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
43404340
exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0;
43414341
const core = __importStar(__webpack_require__(470));
43424342
const github = __importStar(__webpack_require__(469));
4343-
const octokit_helper_1 = __webpack_require__(24);
4343+
const octokit_provider_1 = __webpack_require__(195);
43444344
const url_helper_1 = __webpack_require__(81);
43454345
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
43464346
function getCheckoutInfo(git, ref, commit) {
@@ -4541,7 +4541,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
45414541
const actualHeadSha = match[1];
45424542
if (actualHeadSha !== expectedHeadSha) {
45434543
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
4544-
const octokit = (0, octokit_helper_1.getOctokit)(token, {
4544+
const octokit = (0, octokit_provider_1.getOctokit)(token, {
45454545
baseUrl: baseUrl,
45464546
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload('number')};run_id=${process.env['GITHUB_RUN_ID']};expected_head_sha=${expectedHeadSha};actual_head_sha=${actualHeadSha})`
45474547
});
@@ -11028,7 +11028,7 @@ const path = __importStar(__webpack_require__(622));
1102811028
const retryHelper = __importStar(__webpack_require__(587));
1102911029
const toolCache = __importStar(__webpack_require__(533));
1103011030
const v4_1 = __importDefault(__webpack_require__(826));
11031-
const octokit_helper_1 = __webpack_require__(24);
11031+
const octokit_provider_1 = __webpack_require__(195);
1103211032
const IS_WINDOWS = process.platform === 'win32';
1103311033
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) {
1103411034
return __awaiter(this, void 0, void 0, function* () {
@@ -11089,7 +11089,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
1108911089
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
1109011090
var _a;
1109111091
core.info('Retrieving the default branch name');
11092-
const octokit = (0, octokit_helper_1.getOctokit)(authToken, { baseUrl: baseUrl });
11092+
const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
1109311093
let result;
1109411094
try {
1109511095
// Get the default branch from the repo info
@@ -11121,7 +11121,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
1112111121
exports.getDefaultBranch = getDefaultBranch;
1112211122
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
1112311123
return __awaiter(this, void 0, void 0, function* () {
11124-
const octokit = (0, octokit_helper_1.getOctokit)(authToken, { baseUrl: baseUrl });
11124+
const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
1112511125
const params = {
1112611126
owner: owner,
1112711127
repo: repo,

src/github-api-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path'
66
import * as retryHelper from './retry-helper'
77
import * as toolCache from '@actions/tool-cache'
88
import {default as uuid} from 'uuid/v4'
9-
import {getOctokit, Octokit} from './octokit-helper'
9+
import {getOctokit, Octokit} from './octokit-provider'
1010

1111
const IS_WINDOWS = process.platform === 'win32'
1212

src/ref-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {IGitCommandManager} from './git-command-manager'
22
import * as core from '@actions/core'
33
import * as github from '@actions/github'
4-
import {getOctokit} from './octokit-helper'
4+
import {getOctokit} from './octokit-provider'
55
import {isGhes} from './url-helper'
66

77
export const tagsRefSpec = '+refs/tags/*:refs/tags/*'

0 commit comments

Comments
 (0)