Compare commits

...

6 Commits

Author SHA1 Message Date
6cd32fd936 fix: disable abbreviated commit shas in diff (#3337) 2024-09-16 02:17:19 -07:00
d121e62763 fix: disable diff detection for renames and copies (#3330)
* fix: disable diff detection for renames and copies

* fix format
2024-09-12 04:48:43 -07:00
f4d66f4d5a build(deps-dev): bump typescript from 5.5.4 to 5.6.2 (#3319)
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.5.4 to 5.6.2.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
- [Commits](https://github.com/microsoft/TypeScript/compare/v5.5.4...v5.6.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-10 12:49:31 +00:00
488c869d17 build(deps-dev): bump @types/node from 18.19.48 to 18.19.50 (#3320)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.19.48 to 18.19.50.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-10 12:49:21 +00:00
5354f85616 docs: update readme 2024-09-09 07:01:59 -07:00
8867c4aba1 fix: handle ambiguous argument failure on diff stat (#3312) 2024-09-05 09:23:05 +01:00
8 changed files with 68 additions and 51 deletions

View File

@ -246,26 +246,6 @@ Note that the repository must be checked out on a branch with a remote, it won't
uses: peter-evans/create-pull-request@v7
```
<!--
### Create a project card
To create a project card for the pull request, pass the `pull-request-number` step output to [create-or-update-project-card](https://github.com/peter-evans/create-or-update-project-card) action.
```yml
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
- name: Create or Update Project Card
if: ${{ steps.cpr.outputs.pull-request-number }}
uses: peter-evans/create-or-update-project-card@v2
with:
project-name: My project
column-name: My column
issue-number: ${{ steps.cpr.outputs.pull-request-number }}
```
-->
### Auto-merge
Auto-merge can be enabled on a pull request allowing it to be automatically merged once requirements have been satisfied.

View File

@ -19,14 +19,17 @@ git clone git://127.0.0.1/repos/test-base.git /git/local/repos/test-base
cd /git/local/repos/test-base
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
echo "#test-base" > README.md
echo "#test-base" > README_TEMP.md
git add .
git commit -m "initial commit"
git commit --allow-empty -m "empty commit for tests"
echo "#test-base :sparkles:" > README.md
echo "#test-base :sparkles:" > README_TEMP.md
git add .
git commit -m "add sparkles" -m "Change description:
- updates README.md to add sparkles to the title"
- updates README_TEMP.md to add sparkles to the title"
mv README_TEMP.md README.md
git add .
git commit -m "rename readme"
git push -u
git log -1 --pretty=oneline
git config --global --unset user.email

View File

@ -11,14 +11,15 @@ describe('git-command-manager integration tests', () => {
})
it('tests getCommit', async () => {
const initialCommit = await git.getCommit('HEAD^^')
const emptyCommit = await git.getCommit('HEAD^')
const initialCommit = await git.getCommit('HEAD^^^')
const emptyCommit = await git.getCommit('HEAD^^')
const modifiedCommit = await git.getCommit('HEAD^')
const headCommit = await git.getCommit('HEAD')
expect(initialCommit.subject).toEqual('initial commit')
expect(initialCommit.signed).toBeFalsy()
expect(initialCommit.changes).toEqual([
{mode: '100644', status: 'A', path: 'README.md'}
{mode: '100644', status: 'A', path: 'README_TEMP.md'}
])
expect(emptyCommit.subject).toEqual('empty commit for tests')
@ -27,11 +28,19 @@ describe('git-command-manager integration tests', () => {
expect(emptyCommit.signed).toBeFalsy()
expect(emptyCommit.changes).toEqual([])
expect(headCommit.subject).toEqual('add sparkles')
expect(headCommit.parents[0]).toEqual(emptyCommit.sha)
expect(modifiedCommit.subject).toEqual('add sparkles')
expect(modifiedCommit.parents[0]).toEqual(emptyCommit.sha)
expect(modifiedCommit.signed).toBeFalsy()
expect(modifiedCommit.changes).toEqual([
{mode: '100644', status: 'M', path: 'README_TEMP.md'}
])
expect(headCommit.subject).toEqual('rename readme')
expect(headCommit.parents[0]).toEqual(modifiedCommit.sha)
expect(headCommit.signed).toBeFalsy()
expect(headCommit.changes).toEqual([
{mode: '100644', status: 'M', path: 'README.md'}
{mode: '100644', status: 'A', path: 'README.md'},
{mode: '100644', status: 'D', path: 'README_TEMP.md'}
])
})
})

21
dist/index.js vendored
View File

@ -46,6 +46,7 @@ exports.buildBranchCommits = buildBranchCommits;
exports.createOrUpdateBranch = createOrUpdateBranch;
const core = __importStar(__nccwpck_require__(2186));
const uuid_1 = __nccwpck_require__(5840);
const utils = __importStar(__nccwpck_require__(918));
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
const FETCH_DEPTH_MARGIN = 10;
@ -136,9 +137,19 @@ function isEven(git, branch1, branch2) {
// Return true if the specified number of commits on branch1 and branch2 have a diff
function commitsHaveDiff(git, branch1, branch2, depth) {
return __awaiter(this, void 0, void 0, function* () {
const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim();
const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim();
return diff1 !== diff2;
// Some action use cases lead to the depth being a very large number and the diff fails.
// I've made this check optional for now because it was a fix for an edge case that is
// very rare, anyway.
try {
const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim();
const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim();
return diff1 !== diff2;
}
catch (error) {
core.info('Failed optional check of commits diff; Skipping.');
core.debug(utils.getErrorMessage(error));
return false;
}
});
}
function splitLines(multilineString) {
@ -734,6 +745,8 @@ class GitCommandManager {
'show',
'--raw',
'--cc',
'--no-renames',
'--no-abbrev',
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
ref
]);
@ -749,7 +762,7 @@ class GitCommandManager {
subject: detailLines[4],
body: detailLines.slice(5, endOfBodyIndex).join('\n'),
changes: lines.slice(endOfBodyIndex + 2, -1).map(line => {
const change = line.match(/^:(\d{6}) (\d{6}) \w{7} \w{7} ([AMD])\s+(.*)$/);
const change = line.match(/^:(\d{6}) (\d{6}) \w{40} \w{40} ([AMD])\s+(.*)$/);
if (change) {
return {
mode: change[3] === 'D' ? change[1] : change[2],

16
package-lock.json generated
View File

@ -22,7 +22,7 @@
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.48",
"@types/node": "^18.19.50",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vercel/ncc": "^0.38.1",
@ -38,7 +38,7 @@
"js-yaml": "^4.1.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
}
},
"node_modules/@actions/core": {
@ -1560,9 +1560,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "18.19.48",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.48.tgz",
"integrity": "sha512-7WevbG4ekUcRQSZzOwxWgi5dZmTak7FaxXDoW7xVxPBmKx1rTzfmRLkeCgJzcbBnOV2dkhAPc8cCeT6agocpjg==",
"version": "18.19.50",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.50.tgz",
"integrity": "sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg==",
"dev": true,
"dependencies": {
"undici-types": "~5.26.4"
@ -7756,9 +7756,9 @@
}
},
"node_modules/typescript": {
"version": "5.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
"version": "5.6.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz",
"integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",

View File

@ -42,7 +42,7 @@
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.48",
"@types/node": "^18.19.50",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vercel/ncc": "^0.38.1",
@ -58,6 +58,6 @@
"js-yaml": "^4.1.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
}
}

View File

@ -1,6 +1,7 @@
import * as core from '@actions/core'
import {GitCommandManager, Commit} from './git-command-manager'
import {v4 as uuidv4} from 'uuid'
import * as utils from './utils'
const CHERRYPICK_EMPTY =
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
@ -131,13 +132,22 @@ async function commitsHaveDiff(
branch2: string,
depth: number
): Promise<boolean> {
const diff1 = (
await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])
).stdout.trim()
const diff2 = (
await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])
).stdout.trim()
return diff1 !== diff2
// Some action use cases lead to the depth being a very large number and the diff fails.
// I've made this check optional for now because it was a fix for an edge case that is
// very rare, anyway.
try {
const diff1 = (
await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])
).stdout.trim()
const diff2 = (
await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])
).stdout.trim()
return diff1 !== diff2
} catch (error) {
core.info('Failed optional check of commits diff; Skipping.')
core.debug(utils.getErrorMessage(error))
return false
}
}
function splitLines(multilineString: string): string[] {

View File

@ -159,6 +159,8 @@ export class GitCommandManager {
'show',
'--raw',
'--cc',
'--no-renames',
'--no-abbrev',
`--format=%H%n%T%n%P%n%G?%n%s%n%b%n${endOfBody}`,
ref
])
@ -176,7 +178,7 @@ export class GitCommandManager {
body: detailLines.slice(5, endOfBodyIndex).join('\n'),
changes: lines.slice(endOfBodyIndex + 2, -1).map(line => {
const change = line.match(
/^:(\d{6}) (\d{6}) \w{7} \w{7} ([AMD])\s+(.*)$/
/^:(\d{6}) (\d{6}) \w{40} \w{40} ([AMD])\s+(.*)$/
)
if (change) {
return {