Skip to content

Commit

Permalink
Addressing code review comments for PR #922
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-murray authored Sep 20, 2022
1 parent 092f9bd commit 0ff8af6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 68 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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: ''
```
<!-- end usage -->
Expand Down
39 changes: 25 additions & 14 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as io from '@actions/io'
import * as os from 'os'
import * as path from 'path'
import * as stateHelper from '../lib/state-helper'
import { IGitCommandManager } from '../lib/git-command-manager'
import { IGitSourceSettings } from '../lib/git-source-settings'
import {IGitCommandManager} from '../lib/git-command-manager'
import {IGitSourceSettings} from '../lib/git-source-settings'

const isWindows = process.platform === 'win32'
const testWorkspace = path.join(__dirname, '_temp', 'git-auth-helper')
Expand All @@ -17,7 +17,7 @@ let localGitConfigPath: string
let globalGitConfigPath: string
let runnerTemp: string
let tempHomedir: string
let git: IGitCommandManager & { env: { [key: string]: string } }
let git: IGitCommandManager & {env: {[key: string]: string}}
let settings: IGitSourceSettings
let sshPath: string
let githubServerUrl: string
Expand All @@ -33,7 +33,7 @@ describe('git-auth-helper tests', () => {

beforeEach(() => {
// Mock setSecret
jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => { })
jest.spyOn(core, 'setSecret').mockImplementation((secret: string) => {})

// Mock error/warning/info/debug
jest.spyOn(core, 'error').mockImplementation(jest.fn())
Expand Down Expand Up @@ -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
let expectedServerUrl = 'https://github.com'
if (serverUrl) {
Expand Down Expand Up @@ -101,17 +104,25 @@ describe('git-auth-helper tests', () => {
const configureAuth_configuresAuthHeader =
'configureAuth configures auth header'
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 () => {
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 () => {
await testAuthHeader(configureAuth_AcceptsGitHubServerUrl, 'https://github.com');
await testAuthHeader(
configureAuth_AcceptsGitHubServerUrl,
'https://github.com'
)
})

const configureAuth_configuresAuthHeaderEvenWhenPersistCredentialsFalse =
Expand Down Expand Up @@ -699,17 +710,17 @@ async function setup(testName: string): Promise<void> {
workspace = path.join(testWorkspace, testName, 'workspace')
runnerTemp = path.join(testWorkspace, testName, 'runner-temp')
tempHomedir = path.join(testWorkspace, testName, 'home-dir')
await fs.promises.mkdir(workspace, { recursive: true })
await fs.promises.mkdir(runnerTemp, { recursive: true })
await fs.promises.mkdir(tempHomedir, { recursive: true })
await fs.promises.mkdir(workspace, {recursive: true})
await fs.promises.mkdir(runnerTemp, {recursive: true})
await fs.promises.mkdir(tempHomedir, {recursive: true})
process.env['RUNNER_TEMP'] = runnerTemp
process.env['HOME'] = tempHomedir

// Create git config
globalGitConfigPath = path.join(tempHomedir, '.gitconfig')
await fs.promises.writeFile(globalGitConfigPath, '')
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, '')

git = {
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
default: true
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
runs:
using: node16
Expand Down
100 changes: 50 additions & 50 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,51 +1295,6 @@ module.exports._parse = parse;
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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -4340,7 +4340,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0;
const core = __importStar(__webpack_require__(470));
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);
exports.tagsRefSpec = '+refs/tags/*:refs/tags/*';
function getCheckoutInfo(git, ref, commit) {
Expand Down Expand Up @@ -4541,7 +4541,7 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref
const actualHeadSha = match[1];
if (actualHeadSha !== expectedHeadSha) {
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,
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})`
});
Expand Down Expand Up @@ -11028,7 +11028,7 @@ const path = __importStar(__webpack_require__(622));
const retryHelper = __importStar(__webpack_require__(587));
const toolCache = __importStar(__webpack_require__(533));
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';
function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, baseUrl) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -11089,7 +11089,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
var _a;
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;
try {
// Get the default branch from the repo info
Expand Down Expand Up @@ -11121,7 +11121,7 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
exports.getDefaultBranch = getDefaultBranch;
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
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 = {
owner: owner,
repo: repo,
Expand Down
2 changes: 1 addition & 1 deletion src/github-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path'
import * as retryHelper from './retry-helper'
import * as toolCache from '@actions/tool-cache'
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'

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ref-helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IGitCommandManager} from './git-command-manager'
import * as core from '@actions/core'
import * as github from '@actions/github'
import {getOctokit} from './octokit-helper'
import {getOctokit} from './octokit-provider'
import {isGhes} from './url-helper'

export const tagsRefSpec = '+refs/tags/*:refs/tags/*'
Expand Down

0 comments on commit 0ff8af6

Please sign in to comment.