MOBILE-3501 gulp: Validate last commit message in push task
parent
22257e5b49
commit
719ffa2ff1
19
gulp/git.js
19
gulp/git.js
|
@ -156,6 +156,25 @@ class Git {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the latest titles of the commit messages.
|
||||||
|
*
|
||||||
|
* @param count Number of commits to display.
|
||||||
|
* @param range Show only commits in the specified revision range.
|
||||||
|
* @param path Show only commits that are enough to explain how the files that match the specified paths came to be.
|
||||||
|
* @return Promise resolved with the list of titles.
|
||||||
|
*/
|
||||||
|
async messages(count, range, path) {
|
||||||
|
count = typeof count != 'undefined' ? count : 10;
|
||||||
|
|
||||||
|
const messageList = await this.log(count, range, '%s', path);
|
||||||
|
|
||||||
|
const messages = messageList.split('\n');
|
||||||
|
messages.pop(); // Remove last element, it's an empty string.
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a branch.
|
* Push a branch.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
const inquirer = require('inquirer');
|
||||||
const DevConfig = require('./dev-config');
|
const DevConfig = require('./dev-config');
|
||||||
const Git = require('./git');
|
const Git = require('./git');
|
||||||
const Jira = require('./jira');
|
const Jira = require('./jira');
|
||||||
|
@ -45,6 +46,15 @@ class PushTask {
|
||||||
throw new Error('Cannot push HEAD branch');
|
throw new Error('Cannot push HEAD branch');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keepRunning = await this.validateLastCommitMessage(branch);
|
||||||
|
|
||||||
|
if (!keepRunning) {
|
||||||
|
// Last commit not valid, stop.
|
||||||
|
console.log('Exiting...');
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Push the branch.
|
// Push the branch.
|
||||||
console.log(`Pushing branch ${branch} to remote ${remote}...`);
|
console.log(`Pushing branch ${branch} to remote ${remote}...`);
|
||||||
await Git.push(remote, branch, force);
|
await Git.push(remote, branch, force);
|
||||||
|
@ -120,6 +130,44 @@ class PushTask {
|
||||||
console.log('Setting tracker fields...');
|
console.log('Setting tracker fields...');
|
||||||
await Jira.setCustomFields(branchData.issue, updates);
|
await Jira.setCustomFields(branchData.issue, updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate last commit message comparing it with the branch name.
|
||||||
|
*
|
||||||
|
* @param branch Branch name.
|
||||||
|
* @return True if value is ok or the user wants to continue anyway, false to stop.
|
||||||
|
*/
|
||||||
|
async validateLastCommitMessage(branch) {
|
||||||
|
const branchData = Utils.parseBranch(branch);
|
||||||
|
|
||||||
|
const messages = await Git.messages(1);
|
||||||
|
const message = messages[0];
|
||||||
|
|
||||||
|
const issue = Utils.getIssueFromCommitMessage(message);
|
||||||
|
|
||||||
|
if (!issue || issue != branchData.issue) {
|
||||||
|
if (!issue) {
|
||||||
|
console.log('The issue number could not be found in the commit message.');
|
||||||
|
console.log(`Commit: ${message}`);
|
||||||
|
} else if (issue != branchData.issue) {
|
||||||
|
console.log('The issue number in the last commit does not match the branch being pushed to.');
|
||||||
|
console.log(`Branch: ${branchData.issue} vs. commit: ${issue}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const answer = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'confirm',
|
||||||
|
message: 'Are you sure you want to continue?',
|
||||||
|
default: 'n',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
return answer.confirm == 'y';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PushTask;
|
module.exports = PushTask;
|
||||||
|
|
Loading…
Reference in New Issue