diff --git a/README.md b/README.md index 17eecbe..e966fc5 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,12 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # # Default: ${{ github.token }} token: '' - - # Github slug used to configure local user.name and user.email for git. This is - # required to push a commit from a Github Action Workflow. Set to '' to disable - # this configuration. - # Default: github-action[bot] - git-user: '' + + # Github slug used to configure local user.name and user.email for git. + # This is required to push a commit from a Github Action Workflow + # Set to '' to disable this configuration + # Default: "github-action[bot] + git-config: '' # SSH key used to fetch the repository. The SSH key is configured with the local # git config, which enables your scripts to run authenticated git commands. The diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 6515ff8..7633704 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -1,12 +1,12 @@ import * as core from '@actions/core' import * as fs from 'fs' -import * as gitAuthHelper from '../src/git-auth-helper' +import * as gitAuthHelper from '../lib/git-auth-helper' import * as io from '@actions/io' import * as os from 'os' import * as path from 'path' -import * as stateHelper from '../src/state-helper' -import {IGitCommandManager} from '../src/git-command-manager' -import {IGitSourceSettings} from '../src/git-source-settings' +import * as stateHelper from '../lib/state-helper' +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') @@ -824,8 +824,7 @@ async function setup(testName: string): Promise { sshUser: '', workflowOrganizationId: 123456, setSafeDirectory: true, - githubServerUrl: githubServerUrl, - gitUser: 'github-action[bot]' + githubServerUrl: githubServerUrl } } diff --git a/__test__/git-command-manager.test.ts b/__test__/git-command-manager.test.ts index 414c070..cea73d4 100644 --- a/__test__/git-command-manager.test.ts +++ b/__test__/git-command-manager.test.ts @@ -1,6 +1,6 @@ import * as exec from '@actions/exec' -import * as fshelper from '../src/fs-helper' -import * as commandManager from '../src/git-command-manager' +import * as fshelper from '../lib/fs-helper' +import * as commandManager from '../lib/git-command-manager' let git: commandManager.IGitCommandManager let mockExec = jest.fn() diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index 8899e51..22e9ae6 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -1,9 +1,9 @@ import * as core from '@actions/core' import * as fs from 'fs' -import * as gitDirectoryHelper from '../src/git-directory-helper' +import * as gitDirectoryHelper from '../lib/git-directory-helper' import * as io from '@actions/io' import * as path from 'path' -import {IGitCommandManager} from '../src/git-command-manager' +import {IGitCommandManager} from '../lib/git-command-manager' const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper') let repositoryPath: string diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts index e57da83..9514cb4 100644 --- a/__test__/input-helper.test.ts +++ b/__test__/input-helper.test.ts @@ -1,10 +1,10 @@ import * as core from '@actions/core' -import * as fsHelper from '../src/fs-helper' +import * as fsHelper from '../lib/fs-helper' import * as github from '@actions/github' -import * as inputHelper from '../src/input-helper' +import * as inputHelper from '../lib/input-helper' import * as path from 'path' -import * as workflowContextHelper from '../src/workflow-context-helper' -import {IGitSourceSettings} from '../src/git-source-settings' +import * as workflowContextHelper from '../lib/workflow-context-helper' +import {IGitSourceSettings} from '../lib/git-source-settings' const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE'] const gitHubWorkspace = path.resolve('/checkout-tests/workspace') diff --git a/__test__/ref-helper.test.ts b/__test__/ref-helper.test.ts index c78b976..5c8d76b 100644 --- a/__test__/ref-helper.test.ts +++ b/__test__/ref-helper.test.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' -import * as refHelper from '../src/ref-helper' -import {IGitCommandManager} from '../src/git-command-manager' +import * as refHelper from '../lib/ref-helper' +import {IGitCommandManager} from '../lib/git-command-manager' const commit = '1234567890123456789012345678901234567890' let git: IGitCommandManager diff --git a/__test__/retry-helper.test.ts b/__test__/retry-helper.test.ts index 373ccbb..a5d3f79 100644 --- a/__test__/retry-helper.test.ts +++ b/__test__/retry-helper.test.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import {RetryHelper} from '../src/retry-helper' +import {RetryHelper} from '../lib/retry-helper' let info: string[] let retryHelper: any diff --git a/dist/index.js b/dist/index.js index 1f13658..b5e352a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1357,15 +1357,6 @@ function getSource(settings) { core.setOutput('commit', commitSHA.trim()); // Check for incorrect pull request merge commit yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.githubServerUrl); - if (settings.gitUser) { - if (!(yield git.configExists('user.name', true))) { - yield git.config('user.name', settings.gitUser, true); - } - if (!(yield git.configExists('user.email', true))) { - const userId = yield githubApiHelper.getUserId(settings.gitUser, settings.authToken, settings.githubServerUrl); - yield git.config('user.email', `${userId}+${settings.gitUser}@users.noreply.github.com`, true); - } - } } finally { // Remove auth @@ -1555,7 +1546,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", ({ value: true })); exports.downloadRepository = downloadRepository; exports.getDefaultBranch = getDefaultBranch; -exports.getUserId = getUserId; const assert = __importStar(__nccwpck_require__(9491)); const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); @@ -1673,15 +1663,6 @@ function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) { return Buffer.from(response.data); // response.data is ArrayBuffer }); } -function getUserId(username, authToken, baseUrl) { - return __awaiter(this, void 0, void 0, function* () { - const octokit = github.getOctokit(authToken, { - baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl) - }); - const user = yield octokit.rest.users.getByUsername({ username, }); - return user.data.id; - }); -} /***/ }), @@ -1832,8 +1813,8 @@ function getInputs() { core.debug(`recursive submodules = ${result.nestedSubmodules}`); // Auth token result.authToken = core.getInput('token', { required: true }); - // Git user - result.gitUser = core.getInput('git-user') || 'github-action[bot]'; + // Configure user + result.gitUser = (core.getInput('git-user') || 'github-action[bot]') // SSH result.sshKey = core.getInput('ssh-key'); result.sshKnownHosts = core.getInput('ssh-known-hosts'); diff --git a/package-lock.json b/package-lock.json index 1719332..25753a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2502,11 +2502,10 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", - "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, - "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -5529,13 +5528,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", - "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dev": true, - "license": "MIT", "dependencies": { - "braces": "^3.0.3", + "braces": "^3.0.2", "picomatch": "^2.3.1" }, "engines": { diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index bb44f11..bb4c5a5 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -275,21 +275,14 @@ export async function getSource(settings: IGitSourceSettings): Promise { settings.githubServerUrl ) if (settings.gitUser) { - if (!(await git.configExists('user.name', true))) { + if (!await git.configExists('user.name', true)) { await git.config('user.name', settings.gitUser, true) } - if (!(await git.configExists('user.email', true))) { - const userId = await githubApiHelper.getUserId( - settings.gitUser, - settings.authToken, - settings.githubServerUrl - ) - await git.config( - 'user.email', - `${userId}+${settings.gitUser}@users.noreply.github.com`, - true - ) - } + if (!await git.configExists('user.email', true)) { + + const userId = await githubApiHelper.getUserId(settings.gitUser, settings.authToken, settings.githubServerUrl); + await git.config('user.email', `${userId}+${settings.gitUser}@users.noreply.github.com`, true) + } } } finally { // Remove auth diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index 8e0cd0d..b90b990 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -152,6 +152,6 @@ export async function getUserId( const octokit = github.getOctokit(authToken, { baseUrl: getServerApiUrl(baseUrl) }) - const user = await octokit.rest.users.getByUsername({username}) + const user = await octokit.rest.users.getByUsername({username,}); return user.data.id }