Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
fix: allow opt-out of Fixes/Refs metadata
  • Loading branch information
codebytere committed Aug 14, 2020
commit c429b4505dad318d80c4e38c98009b9a7b41f0a7
10 changes: 8 additions & 2 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const landOptions = {
describe: 'Land a backport PR onto a staging branch',
default: false,
type: 'boolean'
},
skipRefs: {
describe: 'Prevent adding Fixes and Refs information to commit metadata',
default: false,
type: 'boolean'
}
};

Expand Down Expand Up @@ -89,7 +94,8 @@ function handler(argv) {

const provided = [];
for (const type of Object.keys(landOptions)) {
if (type === 'yes') continue; // --yes is not an action
// --yes and --skipRefs are not actions.
if (type === 'yes' || type === 'skipRefs') continue;
if (argv[type]) {
provided.push(type);
}
Expand Down Expand Up @@ -160,7 +166,7 @@ async function main(state, argv, cli, req, dir) {
return;
}
session = new LandingSession(cli, req, dir, argv.prid, argv.backport);
const metadata = await getMetadata(session.argv, cli);
const metadata = await getMetadata(session.argv, argv.skipRefs, cli);
if (argv.backport) {
const split = metadata.metadata.split('\n')[0];
if (split === 'PR-URL: ') {
Expand Down
4 changes: 2 additions & 2 deletions components/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MetadataGenerator = require('../lib/metadata_gen');

const fs = require('fs');

module.exports = async function getMetadata(argv, cli) {
module.exports = async function getMetadata(argv, skipRefs, cli) {
const credentials = await auth({
github: true,
jenkins: true
Expand All @@ -23,7 +23,7 @@ module.exports = async function getMetadata(argv, cli) {
cli.separator('PR info');
summary.display();

const metadata = new MetadataGenerator(data).getMetadata();
const metadata = new MetadataGenerator({ skipRefs, ...data }).getMetadata();
if (!process.stdout.isTTY) {
process.stdout.write(metadata);
}
Expand Down
2 changes: 2 additions & 0 deletions docs/git-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Options:
non-interactively. If an undesirable situation occurs, such as
a pull request or commit check fails, then git node land will
abort. [boolean] [default: false]
--skipRefs Prevent Fixes and Refs information from being added to commit
metadata [boolean] [default: false]


Examples:
Expand Down
18 changes: 13 additions & 5 deletions lib/metadata_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class MetadataGenerator {
* @param {PRData} data
*/
constructor(data) {
const { owner, repo, pr, reviewers, argv } = data;
const { owner, repo, pr, reviewers, argv, skipRefs } = data;
this.owner = owner;
this.skipRefs = skipRefs;
this.repo = repo;
this.pr = pr;
this.reviewers = reviewers;
Expand All @@ -33,10 +34,17 @@ class MetadataGenerator {
const fixes = parser.getFixes();
const refs = parser.getRefs();
const altPrUrl = parser.getAltPrUrl();
const meta = [
...fixes.map((fix) => `Fixes: ${fix}`),
...refs.map((ref) => `Refs: ${ref}`)
];

const meta = [];

// If there are multiple commits in a PR, we may not want to add
// Fixes/Refs metadata to all of them.
if (!this.skipRefs) {
// Map all issues fixed by the commit(s) in this PR.
meta.push(...fixes.map((fix) => `Fixes: ${fix}`));
// Map all issues referenced by the commit(s) in this PR.
meta.push(...refs.map((ref) => `Refs: ${ref}`));
}
const backport = this.argv ? this.argv.backport : undefined;
if (backport) {
meta.unshift(`Backport-PR-URL: ${prUrl}`);
Expand Down