Addressing code review comments for PR #922

This commit is contained in:
Peter Murray 2022-09-20 07:41:19 +00:00 committed by GitHub
parent 092f9bd613
commit 0ff8af6944
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 68 deletions

View file

@ -100,7 +100,8 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
# The base URL for the GitHub instance that you are trying to clone from, will use # The base URL for the GitHub instance that you are trying to clone from, will use
# environment defaults to fetch from the same instance that the workflow is # environment defaults to fetch from the same instance that the workflow is
# running from unless specified. # running from unless specified. Example URLs are https://github.com or
# https://my-ghes-server.example.com
github-server-url: '' github-server-url: ''
``` ```
<!-- end usage --> <!-- end usage -->

View file

@ -5,8 +5,8 @@ import * as io from '@actions/io'
import * as os from 'os' import * as os from 'os'
import * as path from 'path' import * as path from 'path'
import * as stateHelper from '../lib/state-helper' import * as stateHelper from '../lib/state-helper'
import { IGitCommandManager } from '../lib/git-command-manager' import {IGitCommandManager} from '../lib/git-command-manager'
import { IGitSourceSettings } from '../lib/git-source-settings' import {IGitSourceSettings} from '../lib/git-source-settings'
const isWindows = process.platform === 'win32' const isWindows = process.platform === 'win32'
const testWorkspace = path.join(__dirname, '_temp', 'git-auth-helper') const testWorkspace = path.join(__dirname, '_temp', 'git-auth-helper')
@ -17,7 +17,7 @@ let localGitConfigPath: string
let globalGitConfigPath: string let globalGitConfigPath: string
let runnerTemp: string let runnerTemp: string
let tempHomedir: string let tempHomedir: string
let git: IGitCommandManager & { env: { [key: string]: string } } let git: IGitCommandManager & {env: {[key: string]: string}}
let settings: IGitSourceSettings let settings: IGitSourceSettings
let sshPath: string let sshPath: string
let githubServerUrl: string let githubServerUrl: string
@ -33,7 +33,7 @@ describe('git-auth-helper tests', () => {
beforeEach(() => { beforeEach(() => {
// Mock setSecret // Mock setSecret
jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => { }) jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => {})
// Mock error/warning/info/debug // Mock error/warning/info/debug
jest.spyOn(core, 'error').mockImplementation(jest.fn()) jest.spyOn(core, 'error').mockImplementation(jest.fn())
@ -68,7 +68,10 @@ describe('git-auth-helper tests', () => {
} }
}) })
async function testAuthHeader(testName: string, serverUrl: string | undefined = undefined) { async function testAuthHeader(
testName: string,
serverUrl: string | undefined = undefined
) {
// Arrange // Arrange
let expectedServerUrl = 'https://github.com' let expectedServerUrl = 'https://github.com'
if (serverUrl) { if (serverUrl) {
@ -101,17 +104,25 @@ describe('git-auth-helper tests', () => {
const configureAuth_configuresAuthHeader = const configureAuth_configuresAuthHeader =
'configureAuth configures auth header' 'configureAuth configures auth header'
it(configureAuth_configuresAuthHeader, async () => { it(configureAuth_configuresAuthHeader, async () => {
await testAuthHeader(configureAuth_configuresAuthHeader); await testAuthHeader(configureAuth_configuresAuthHeader)
}) })
const configureAuth_AcceptsGitHubServerUrl = 'inject https://my-ghes-server.com as github server url' const configureAuth_AcceptsGitHubServerUrl =
'inject https://my-ghes-server.com as github server url'
it(configureAuth_AcceptsGitHubServerUrl, async () => { it(configureAuth_AcceptsGitHubServerUrl, async () => {
await testAuthHeader(configureAuth_AcceptsGitHubServerUrl, 'https://my-ghes-server.com'); await testAuthHeader(
configureAuth_AcceptsGitHubServerUrl,
'https://my-ghes-server.com'
)
}) })
const configureAuth_AcceptsGitHubServerUrlSetToGHEC = 'inject https://github.com as github server url' const configureAuth_AcceptsGitHubServerUrlSetToGHEC =
'inject https://github.com as github server url'
it(configureAuth_AcceptsGitHubServerUrlSetToGHEC, async () => { it(configureAuth_AcceptsGitHubServerUrlSetToGHEC, async () => {
await testAuthHeader(configureAuth_AcceptsGitHubServerUrl, 'https://github.com'); await testAuthHeader(
configureAuth_AcceptsGitHubServerUrl,
'https://github.com'
)
}) })
const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse = const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
@ -699,9 +710,9 @@ async function setup(testName: string): Promise<void> {
workspace = path.join(testWorkspace, testName, 'workspace') workspace = path.join(testWorkspace, testName, 'workspace')
runnerTemp = path.join(testWorkspace, testName, 'runner-temp') runnerTemp = path.join(testWorkspace, testName, 'runner-temp')
tempHomedir = path.join(testWorkspace, testName, 'home-dir') tempHomedir = path.join(testWorkspace, testName, 'home-dir')
await fs.promises.mkdir(workspace, { recursive: true }) await fs.promises.mkdir(workspace, {recursive: true})
await fs.promises.mkdir(runnerTemp, { recursive: true }) await fs.promises.mkdir(runnerTemp, {recursive: true})
await fs.promises.mkdir(tempHomedir, { recursive: true }) await fs.promises.mkdir(tempHomedir, {recursive: true})
process.env['RUNNER_TEMP'] = runnerTemp process.env['RUNNER_TEMP'] = runnerTemp
process.env['HOME'] = tempHomedir process.env['HOME'] = tempHomedir
@ -709,7 +720,7 @@ async function setup(testName: string): Promise<void> {
globalGitConfigPath = path.join(tempHomedir, '.gitconfig') globalGitConfigPath = path.join(tempHomedir, '.gitconfig')
await fs.promises.writeFile(globalGitConfigPath, '') await fs.promises.writeFile(globalGitConfigPath, '')
localGitConfigPath = path.join(workspace, '.git', 'config') localGitConfigPath = path.join(workspace, '.git', 'config')
await fs.promises.mkdir(path.dirname(localGitConfigPath), { recursive: true }) await fs.promises.mkdir(path.dirname(localGitConfigPath), {recursive: true})
await fs.promises.writeFile(localGitConfigPath, '') await fs.promises.writeFile(localGitConfigPath, '')
git = { git = {

View file

@ -72,7 +72,7 @@ inputs:
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>` description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
default: true default: true
github-server-url: github-server-url:
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
required: false required: false
runs: runs:
using: node16 using: node16

100
dist/index.js vendored
View file

@ -1295,51 +1295,6 @@ module.exports._parse = parse;
module.exports._enoent = enoent; module.exports._enoent = enoent;
/***/ }),
/***/ 24:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOctokit = exports.Octokit = void 0;
const github = __importStar(__webpack_require__(469));
const url_helper_1 = __webpack_require__(81);
// Centralize all Octokit references by re-exporting
var rest_1 = __webpack_require__(0);
Object.defineProperty(exports, "Octokit", { enumerable: true, get: function () { return rest_1.Octokit; } });
function getOctokit(authToken, opts) {
const options = {
baseUrl: (0, url_helper_1.getServerApiUrl)(opts.baseUrl)
};
if (opts.userAgent) {
options.userAgent = opts.userAgent;
}
return new github.GitHub(authToken, options);
}
exports.getOctokit = getOctokit;
/***/ }), /***/ }),
/***/ 26: /***/ 26:
@ -4125,6 +4080,51 @@ function authenticationPlugin(octokit, options) {
} }
/***/ }),
/***/ 195:
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOctokit = exports.Octokit = void 0;
const github = __importStar(__webpack_require__(469));
const url_helper_1 = __webpack_require__(81);
// Centralize all Octokit references by re-exporting
var rest_1 = __webpack_require__(0);
Object.defineProperty(exports, "Octokit", { enumerable: true, get: function () { return rest_1.Octokit; } });
function getOctokit(authToken, opts) {
const options = {
baseUrl: (0, url_helper_1.getServerApiUrl)(opts.baseUrl)
};
if (opts.userAgent) {
options.userAgent = opts.userAgent;
}
return new github.GitHub(authToken, options);
}
exports.getOctokit = getOctokit;
/***/ }), /***/ }),
/***/ 197: /***/ 197:
@ -4340,7 +4340,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0; exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0;
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const github = __importStar(__webpack_require__(469)); const github = __importStar(__webpack_require__(469));
const octokit_helper_1 = __webpack_require__(24); const octokit_provider_1 = __webpack_require__(195);
const url_helper_1 = __webpack_require__(81); const url_helper_1 = __webpack_require__(81);
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*'; exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
function getCheckoutInfo(git, ref, commit) { function getCheckoutInfo(git, ref, commit) {
@ -4541,7 +4541,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
const actualHeadSha = match[1]; const actualHeadSha = match[1];
if (actualHeadSha !== expectedHeadSha) { if (actualHeadSha !== expectedHeadSha) {
core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`); core.debug(`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`);
const octokit = (0, octokit_helper_1.getOctokit)(token, { const octokit = (0, octokit_provider_1.getOctokit)(token, {
baseUrl: baseUrl, baseUrl: baseUrl,
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})` 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})`
}); });
@ -11028,7 +11028,7 @@ const path = __importStar(__webpack_require__(622));
const retryHelper = __importStar(__webpack_require__(587)); const retryHelper = __importStar(__webpack_require__(587));
const toolCache = __importStar(__webpack_require__(533)); const toolCache = __importStar(__webpack_require__(533));
const v4_1 = __importDefault(__webpack_require__(826)); const v4_1 = __importDefault(__webpack_require__(826));
const octokit_helper_1 = __webpack_require__(24); const octokit_provider_1 = __webpack_require__(195);
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) { function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -11089,7 +11089,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
var _a; var _a;
core.info('Retrieving the default branch name'); core.info('Retrieving the default branch name');
const octokit = (0, octokit_helper_1.getOctokit)(authToken, { baseUrl: baseUrl }); const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
let result; let result;
try { try {
// Get the default branch from the repo info // Get the default branch from the repo info
@ -11121,7 +11121,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
exports.getDefaultBranch = getDefaultBranch; exports.getDefaultBranch = getDefaultBranch;
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) { function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = (0, octokit_helper_1.getOctokit)(authToken, { baseUrl: baseUrl }); const octokit = (0, octokit_provider_1.getOctokit)(authToken, { baseUrl: baseUrl });
const params = { const params = {
owner: owner, owner: owner,
repo: repo, repo: repo,

View file

@ -6,7 +6,7 @@ import * as path from 'path'
import * as retryHelper from './retry-helper' import * as retryHelper from './retry-helper'
import * as toolCache from '@actions/tool-cache' import * as toolCache from '@actions/tool-cache'
import {default as uuid} from 'uuid/v4' import {default as uuid} from 'uuid/v4'
import {getOctokit, Octokit} from './octokit-helper' import {getOctokit, Octokit} from './octokit-provider'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'

View file

@ -1,7 +1,7 @@
import {IGitCommandManager} from './git-command-manager' import {IGitCommandManager} from './git-command-manager'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as github from '@actions/github' import * as github from '@actions/github'
import {getOctokit} from './octokit-helper' import {getOctokit} from './octokit-provider'
import {isGhes} from './url-helper' import {isGhes} from './url-helper'
export const tagsRefSpec = '+refs/tags/*:refs/tags/*' export const tagsRefSpec = '+refs/tags/*:refs/tags/*'