Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: 'you must provide GITHUB_TOKEN to this input if checkAllCommitMessages is true'
required: false
default: 'false'
excludUsers:
description: 'you must provide list of users to exclude compliance check'
required: false
default: '[]'
runs:
using: node16
main: dist/index.js
Expand Down
43 changes: 33 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ function getInputs() {
// Get checkAllCommitMessages
const checkAllCommitMessagesStr = core.getInput('checkAllCommitMessages');
core.debug(`checkAllCommitMessages: ${checkAllCommitMessagesStr}`);
const excludUsersList = core.getInput('excludUsers');
core.info(`Excluding commits by users: ${excludUsersList}`);
// Set pullRequestOptions
const pullRequestOptions = {
ignoreTitle: excludeTitleStr
Expand All @@ -220,7 +222,8 @@ function getInputs() {
checkAllCommitMessages: checkAllCommitMessagesStr
? checkAllCommitMessagesStr === 'true'
: /* default */ false,
accessToken: core.getInput('accessToken')
accessToken: core.getInput('accessToken'),
excludUsersList: excludUsersList
};
core.debug(`accessToken: ${pullRequestOptions.accessToken}`);
// Get commit messages
Expand All @@ -242,6 +245,8 @@ function getMessages(pullRequestOptions) {
core.debug(` - pullRequestOptions: ${JSON.stringify(pullRequestOptions, null, 2)}`);
const messages = [];
core.debug(` - eventName: ${github.context.eventName}`);
// core.info(` - context: ${JSON.stringify(github.context)}`)
core.debug(` - PR: ${github.context.actor}`);
switch (github.context.eventName) {
case 'pull_request_target':
case 'pull_request': {
Expand All @@ -257,7 +262,7 @@ function getMessages(pullRequestOptions) {
if (!github.context.payload.pull_request.title) {
throw new Error('No title found in the pull_request.');
}
message += github.context.payload.pull_request.title;
message += `PR Title: ${github.context.payload.pull_request.title}`;
}
else {
core.debug(' - skipping title');
Expand Down Expand Up @@ -292,7 +297,7 @@ function getMessages(pullRequestOptions) {
!github.context.payload.repository.owner.name)) {
throw new Error('No owner found in the repository.');
}
const commitMessages = yield getCommitMessagesFromPullRequest(pullRequestOptions.accessToken, (_a = github.context.payload.repository.owner.name) !== null && _a !== void 0 ? _a : github.context.payload.repository.owner.login, github.context.payload.repository.name, github.context.payload.pull_request.number);
const commitMessages = yield getCommitMessagesFromPullRequest(pullRequestOptions.accessToken, (_a = github.context.payload.repository.owner.name) !== null && _a !== void 0 ? _a : github.context.payload.repository.owner.login, github.context.payload.repository.name, github.context.payload.pull_request.number, pullRequestOptions.excludUsersList);
for (message of commitMessages) {
if (message) {
messages.push(message);
Expand All @@ -311,7 +316,7 @@ function getMessages(pullRequestOptions) {
break;
}
for (const i in github.context.payload.commits) {
if (github.context.payload.commits[i].message) {
if (github.context.payload.commits[i].message && !pullRequestOptions.excludUsersList.includes(github.context.payload.commits[i].author.name)) {
messages.push(github.context.payload.commits[i].message);
}
}
Expand All @@ -324,27 +329,32 @@ function getMessages(pullRequestOptions) {
return messages;
});
}
function getCommitMessagesFromPullRequest(accessToken, repositoryOwner, repositoryName, pullRequestNumber) {
function getCommitMessagesFromPullRequest(accessToken, repositoryOwner, repositoryName, pullRequestNumber, excludUsersList) {
return __awaiter(this, void 0, void 0, function* () {
core.debug('Get messages from pull request...');
core.debug(` - accessToken: ${accessToken}`);
core.debug(` - repositoryOwner: ${repositoryOwner}`);
core.debug(` - repositoryName: ${repositoryName}`);
core.debug(` - pullRequestNumber: ${pullRequestNumber}`);
core.debug(` - excludUsersList: ${excludUsersList}`);
const query = `
query commitMessages(
$repositoryOwner: String!
$repositoryName: String!
$pullRequestNumber: Int!
$numberOfCommits: Int = 100
) {
)
{
repository(owner: $repositoryOwner, name: $repositoryName) {
pullRequest(number: $pullRequestNumber) {
commits(last: $numberOfCommits) {
edges {
node {
commit {
message
author {
name
}
}
}
}
Expand All @@ -368,10 +378,23 @@ function getCommitMessagesFromPullRequest(accessToken, repositoryOwner, reposito
const repository = response.repository;
core.debug(` - response: ${JSON.stringify(repository, null, 2)}`);
let messages = [];
var edgedata = repository.pullRequest.commits.edges;
var edgedataLength = +Object.keys(edgedata).length;
for (let i = 0; i < edgedataLength; i++) {
if (excludUsersList.includes(edgedata[i].node.commit.author.name)) {
delete edgedata[i];
}
}
core.debug(`edgedata: ${JSON.stringify(edgedata)}`);
if (repository.pullRequest) {
messages = repository.pullRequest.commits.edges.map(function (edge) {
return edge.node.commit.message;
});
if (edgedata.filter(obj => obj !== null) && edgedata.filter(obj => obj !== null).length > 0) {
messages = edgedata.map(function (edge) {
return edge.node.commit.message;
});
}
else {
messages = [];
}
}
return messages;
});
Expand Down Expand Up @@ -448,7 +471,7 @@ function run() {
try {
const checkerArguments = yield inputHelper.getInputs();
if (checkerArguments.messages.length === 0) {
core.info(`No commits found in the payload, skipping check.`);
core.info(`No commits found in the payload for relevent included users, skipping check.`);
}
else {
yield commitMessageChecker.checkCommitMessages(checkerArguments);
Expand Down
Loading