fix: incorrect branch name for issue_comment event (#1625)
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
15f38d6693
commit
3415b43780
108
.github/workflows/issue-comment-test.yml
vendored
108
.github/workflows/issue-comment-test.yml
vendored
@ -34,6 +34,59 @@ jobs:
|
|||||||
shell:
|
shell:
|
||||||
bash
|
bash
|
||||||
|
|
||||||
|
- name: Run changed-files for old new filenames test rename
|
||||||
|
id: changed-files-all-old-new-renamed-files
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
base_sha: d1c0ee4
|
||||||
|
sha: 4d04215
|
||||||
|
fetch_depth: 60000
|
||||||
|
include_all_old_new_renamed_files: true
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check all_old_new_renamed_files output on non windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test/test rename 1.txt,test/test rename-1.txt') && runner.os != 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to include (test/test rename 1.txt,test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check all_old_new_renamed_files output on windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test\\test rename 1.txt,test\\test rename-1.txt') && runner.os == 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to not include (test\\test rename 1.txt,test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check the renamed_files output on non windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test/test rename-1.txt') && runner.os != 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to include (test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check the renamed_files output on windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test\\test rename-1.txt') && runner.os == 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to not include (test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
issue_commented:
|
issue_commented:
|
||||||
# This job only runs for issue comments
|
# This job only runs for issue comments
|
||||||
name: Issue comment
|
name: Issue comment
|
||||||
@ -63,4 +116,57 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo '${{ toJSON(steps.changed-files.outputs) }}'
|
echo '${{ toJSON(steps.changed-files.outputs) }}'
|
||||||
shell:
|
shell:
|
||||||
bash
|
bash
|
||||||
|
|
||||||
|
- name: Run changed-files for old new filenames test rename
|
||||||
|
id: changed-files-all-old-new-renamed-files
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
base_sha: d1c0ee4
|
||||||
|
sha: 4d04215
|
||||||
|
fetch_depth: 60000
|
||||||
|
include_all_old_new_renamed_files: true
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check all_old_new_renamed_files output on non windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test/test rename 1.txt,test/test rename-1.txt') && runner.os != 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to include (test/test rename 1.txt,test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check all_old_new_renamed_files output on windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test\\test rename 1.txt,test\\test rename-1.txt') && runner.os == 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to not include (test\\test rename 1.txt,test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check the renamed_files output on non windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test/test rename-1.txt') && runner.os != 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to include (test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
|
- name: Check the renamed_files output on windows platform
|
||||||
|
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test\\test rename-1.txt') && runner.os == 'Windows'"
|
||||||
|
run: |
|
||||||
|
echo "Invalid output: Expected to not include (test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
|
||||||
|
exit 1
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
23
dist/index.js
generated
vendored
23
dist/index.js
generated
vendored
@ -915,7 +915,7 @@ const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0
|
|||||||
const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
|
const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
var _h, _j, _k;
|
var _h, _j, _k;
|
||||||
let targetBranch = env.GITHUB_REF_NAME;
|
let targetBranch = env.GITHUB_REF_NAME;
|
||||||
const currentBranch = targetBranch;
|
let currentBranch = targetBranch;
|
||||||
let initialCommit = false;
|
let initialCommit = false;
|
||||||
if (!inputs.skipInitialFetch) {
|
if (!inputs.skipInitialFetch) {
|
||||||
if (isShallow) {
|
if (isShallow) {
|
||||||
@ -982,6 +982,13 @@ const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow,
|
|||||||
const currentSha = yield getCurrentSHA({ inputs, workingDirectory });
|
const currentSha = yield getCurrentSHA({ inputs, workingDirectory });
|
||||||
let previousSha = inputs.baseSha;
|
let previousSha = inputs.baseSha;
|
||||||
const diff = '..';
|
const diff = '..';
|
||||||
|
const currentBranchName = yield (0, utils_1.getCurrentBranchName)({ cwd: workingDirectory });
|
||||||
|
if (currentBranchName &&
|
||||||
|
currentBranchName !== 'HEAD' &&
|
||||||
|
(currentBranchName !== targetBranch || currentBranchName !== currentBranch)) {
|
||||||
|
targetBranch = currentBranchName;
|
||||||
|
currentBranch = currentBranchName;
|
||||||
|
}
|
||||||
if (previousSha && currentSha && currentBranch && targetBranch) {
|
if (previousSha && currentSha && currentBranch && targetBranch) {
|
||||||
if (previousSha === currentSha) {
|
if (previousSha === currentSha) {
|
||||||
core.error(`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`);
|
core.error(`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`);
|
||||||
@ -1896,7 +1903,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.setArrayOutput = exports.getOutputKey = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.getDirNamesIncludeFilesPattern = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.exists = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.setArrayOutput = exports.getOutputKey = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.getDirNamesIncludeFilesPattern = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getCurrentBranchName = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.exists = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
||||||
/*global AsyncIterableIterator*/
|
/*global AsyncIterableIterator*/
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
@ -2404,6 +2411,18 @@ const getRemoteBranchHeadSha = ({ cwd, branch }) => __awaiter(void 0, void 0, vo
|
|||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
});
|
});
|
||||||
exports.getRemoteBranchHeadSha = getRemoteBranchHeadSha;
|
exports.getRemoteBranchHeadSha = getRemoteBranchHeadSha;
|
||||||
|
const getCurrentBranchName = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
||||||
|
cwd,
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: !core.isDebug()
|
||||||
|
});
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return stdout.trim();
|
||||||
|
});
|
||||||
|
exports.getCurrentBranchName = getCurrentBranchName;
|
||||||
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
|
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
|
||||||
cwd,
|
cwd,
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -5,6 +5,7 @@ import {Env} from './env'
|
|||||||
import {Inputs} from './inputs'
|
import {Inputs} from './inputs'
|
||||||
import {
|
import {
|
||||||
canDiffCommits,
|
canDiffCommits,
|
||||||
|
getCurrentBranchName,
|
||||||
getHeadSha,
|
getHeadSha,
|
||||||
getParentSha,
|
getParentSha,
|
||||||
getPreviousGitTag,
|
getPreviousGitTag,
|
||||||
@ -90,7 +91,7 @@ export const getSHAForNonPullRequestEvent = async (
|
|||||||
isTag: boolean
|
isTag: boolean
|
||||||
): Promise<DiffResult> => {
|
): Promise<DiffResult> => {
|
||||||
let targetBranch = env.GITHUB_REF_NAME
|
let targetBranch = env.GITHUB_REF_NAME
|
||||||
const currentBranch = targetBranch
|
let currentBranch = targetBranch
|
||||||
let initialCommit = false
|
let initialCommit = false
|
||||||
|
|
||||||
if (!inputs.skipInitialFetch) {
|
if (!inputs.skipInitialFetch) {
|
||||||
@ -163,6 +164,16 @@ export const getSHAForNonPullRequestEvent = async (
|
|||||||
const currentSha = await getCurrentSHA({inputs, workingDirectory})
|
const currentSha = await getCurrentSHA({inputs, workingDirectory})
|
||||||
let previousSha = inputs.baseSha
|
let previousSha = inputs.baseSha
|
||||||
const diff = '..'
|
const diff = '..'
|
||||||
|
const currentBranchName = await getCurrentBranchName({cwd: workingDirectory})
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentBranchName &&
|
||||||
|
currentBranchName !== 'HEAD' &&
|
||||||
|
(currentBranchName !== targetBranch || currentBranchName !== currentBranch)
|
||||||
|
) {
|
||||||
|
targetBranch = currentBranchName
|
||||||
|
currentBranch = currentBranchName
|
||||||
|
}
|
||||||
|
|
||||||
if (previousSha && currentSha && currentBranch && targetBranch) {
|
if (previousSha && currentSha && currentBranch && targetBranch) {
|
||||||
if (previousSha === currentSha) {
|
if (previousSha === currentSha) {
|
||||||
|
22
src/utils.ts
22
src/utils.ts
@ -696,6 +696,28 @@ export const getRemoteBranchHeadSha = async ({
|
|||||||
return stdout.trim()
|
return stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getCurrentBranchName = async ({
|
||||||
|
cwd
|
||||||
|
}: {
|
||||||
|
cwd: string
|
||||||
|
}): Promise<string> => {
|
||||||
|
const {stdout, exitCode} = await exec.getExecOutput(
|
||||||
|
'git',
|
||||||
|
['rev-parse', '--abbrev-ref', 'HEAD'],
|
||||||
|
{
|
||||||
|
cwd,
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: !core.isDebug()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return stdout.trim()
|
||||||
|
}
|
||||||
|
|
||||||
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
|
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
|
||||||
const {stdout, exitCode} = await exec.getExecOutput(
|
const {stdout, exitCode} = await exec.getExecOutput(
|
||||||
'git',
|
'git',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user