Skip to content

Commit 8a75f6d

Browse files
committed
finish up
1 parent af3ca5a commit 8a75f6d

File tree

8 files changed

+81
-15
lines changed

8 files changed

+81
-15
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"simple-git": "3.28.0",
2222
},
2323
"devDependencies": {
24+
"@octokit/webhooks-types": "7.6.1",
2425
"@swc/jest": "0.2.39",
2526
"@total-typescript/ts-reset": "0.6.1",
2627
"@types/bluebird": "3.5.42",
@@ -265,6 +266,8 @@
265266

266267
"@octokit/types": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/openapi-types": "^22.2.0" } }, "sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ=="],
267268

269+
"@octokit/webhooks-types": ["@octokit/[email protected]", "", {}, "sha512-S8u2cJzklBC0FgTwWVLaM8tMrDuDMVE4xiTK4EYXM9GntyvrdbSoxqDQa+Fh57CCNApyIpyeqPhhFEmHPfrXgw=="],
270+
268271
"@pkgjs/parseargs": ["@pkgjs/[email protected]", "", {}, "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg=="],
269272

270273
"@pkgr/core": ["@pkgr/[email protected]", "", {}, "sha512-YLT9Zo3oNPJoBjBc4q8G2mjU4tqIbf5CEOORbUUr48dCD9q3umJ3IPlVqOqDakPfd2HuwccBaqlGhN4Gmr5OWg=="],

dist/813.index.js

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/813.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"simple-git": "3.28.0"
2323
},
2424
"devDependencies": {
25+
"@octokit/webhooks-types": "7.6.1",
2526
"@swc/jest": "0.2.39",
2627
"@total-typescript/ts-reset": "0.6.1",
2728
"@types/bluebird": "3.5.42",

src/helpers/create-batched-commit-message.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ limitations under the License.
1212
*/
1313

1414
import { context } from '@actions/github';
15-
import { info } from '@actions/core';
15+
import { error } from '@actions/core';
16+
import { PushEvent } from '@octokit/webhooks-types';
1617

17-
export const createBatchedCommitMessage = async () => {
18-
info(JSON.stringify(context.payload));
18+
export const createBatchedCommitMessage = () => {
19+
const eventPayload = context.payload as PushEvent;
20+
if (!('commits' in eventPayload)) {
21+
error('No commits found in the event payload.');
22+
return;
23+
}
24+
return eventPayload.commits
25+
.map(commit => {
26+
const prNumberMatch = commit.message.match(/\(#(\d+)\)/)?.[0] ?? '';
27+
const messageWithoutPrNumber = commit.message.replace(prNumberMatch, '').trim();
28+
const truncatedMessage = messageWithoutPrNumber.slice(0, 50);
29+
if (truncatedMessage.length < messageWithoutPrNumber.length) {
30+
return `${truncatedMessage}... ${prNumberMatch ?? 'PR unknown'}`;
31+
}
32+
return commit.message;
33+
})
34+
.join(' and ');
1935
};

src/types/github.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export type SinglePullRequest = PullRequestList[number];
2727
export type IssueLabels = IssueList[number]['labels'];
2828
export type PullRequestBranchesList = RestEndpointMethodTypes['repos']['listBranches']['response']['data'];
2929
export type ChangedFilesList = RestEndpointMethodTypes['pulls']['listFiles']['response']['data'];
30-
export type ProjectListResponse = RestEndpointMethodTypes['projects']['listForRepo']['response'];
31-
export type ColumnListResponse = RestEndpointMethodTypes['projects']['listColumns']['response'];
3230
export type ChecksUpdateConclusion = RestEndpointMethodTypes['checks']['update']['parameters']['conclusion'];
3331
export type MembersInOrg = RestEndpointMethodTypes['teams']['listMembersInOrg']['response']['data'];
3432
export type MembersInOrgParams = RestEndpointMethodTypes['teams']['listMembersInOrg']['parameters'];

test/helpers/create-batched-commit-message.test.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,53 @@ limitations under the License.
1212
*/
1313

1414
import { createBatchedCommitMessage } from '../../src/helpers/create-batched-commit-message';
15+
import { context } from '@actions/github';
1516

1617
jest.mock('@actions/core');
1718
jest.mock('@actions/github', () => ({
18-
context: { repo: { repo: 'repo', owner: 'owner' }, issue: { number: 123 } },
19-
getOctokit: jest.fn(() => ({
20-
rest: {}
21-
}))
19+
context: { payload: {} }
2220
}));
2321

2422
describe('createBatchedCommitMessage', () => {
2523
beforeEach(() => {
26-
createBatchedCommitMessage();
24+
context.payload.commits = [
25+
{
26+
id: '1234567890abcdef',
27+
message: 'Fix issue (#1)',
28+
author: { name: 'John Doe', email: '' }
29+
},
30+
{
31+
id: '1234567891abcdef',
32+
message: 'Fix another issue (#2)',
33+
author: { name: 'Jane Doe', email: '' }
34+
}
35+
];
2736
});
37+
it('should generate combined commit message', () => {
38+
const result = createBatchedCommitMessage();
39+
expect(result).toBe('Fix issue (#1) and Fix another issue (#2)');
40+
});
41+
});
2842

29-
it('should pass', () => {
30-
expect(false).toBe(true);
43+
describe('createBatchedCommitMessage', () => {
44+
beforeEach(() => {
45+
context.payload.commits = [
46+
{
47+
id: '1234567890abcdef',
48+
message: 'Fix a really really really really really long issue (#1)',
49+
author: { name: 'John Doe', email: '' }
50+
},
51+
{
52+
id: '1234567891abcdef',
53+
message: 'Fix another really really really really really long issue (#2)',
54+
author: { name: 'Jane Doe', email: '' }
55+
}
56+
];
57+
});
58+
it('should truncate the message', () => {
59+
const result = createBatchedCommitMessage();
60+
expect(result).toBe(
61+
'Fix a really really really really really long issu... (#1) and Fix another really really really really really lon... (#2)'
62+
);
3163
});
3264
});

0 commit comments

Comments
 (0)