Skip to content

Commit 0dc64de

Browse files
committed
fix: allow opt-out of Fixes/Refs metadata
1 parent fd566e2 commit 0dc64de

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

components/git/land.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ const landOptions = {
4242
describe: 'Land a backport PR onto a staging branch',
4343
default: false,
4444
type: 'boolean'
45+
},
46+
skipRefs: {
47+
describe: 'Prevent Fixes and Refs information from being added to commit metadata',
48+
default: false,
49+
type: 'boolean'
4550
}
4651
};
4752

@@ -89,7 +94,8 @@ function handler(argv) {
8994

9095
const provided = [];
9196
for (const type of Object.keys(landOptions)) {
92-
if (type === 'yes') continue; // --yes is not an action
97+
// --yes and --skipRefs are not actions.
98+
if (type === 'yes' || type === 'skipRefs') continue;
9399
if (argv[type]) {
94100
provided.push(type);
95101
}
@@ -160,7 +166,7 @@ async function main(state, argv, cli, req, dir) {
160166
return;
161167
}
162168
session = new LandingSession(cli, req, dir, argv.prid, argv.backport);
163-
const metadata = await getMetadata(session.argv, cli);
169+
const metadata = await getMetadata(session.argv, argv.skipRefs, cli);
164170
if (argv.backport) {
165171
const split = metadata.metadata.split('\n')[0];
166172
if (split === 'PR-URL: ') {

components/metadata.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const MetadataGenerator = require('../lib/metadata_gen');
99

1010
const fs = require('fs');
1111

12-
module.exports = async function getMetadata(argv, cli) {
12+
module.exports = async function getMetadata(argv, skipRefs, cli) {
1313
const credentials = await auth({
1414
github: true,
1515
jenkins: true
@@ -23,7 +23,7 @@ module.exports = async function getMetadata(argv, cli) {
2323
cli.separator('PR info');
2424
summary.display();
2525

26-
const metadata = new MetadataGenerator(data).getMetadata();
26+
const metadata = new MetadataGenerator({ skipRefs, ...data }).getMetadata();
2727
if (!process.stdout.isTTY) {
2828
process.stdout.write(metadata);
2929
}

docs/git-node.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Options:
4747
non-interactively. If an undesirable situation occurs, such as
4848
a pull request or commit check fails, then git node land will
4949
abort. [boolean] [default: false]
50+
--skipRefs Prevent Fixes and Refs information from being added to commit
51+
metadata [boolean] [default: false]
5052
5153
5254
Examples:

lib/metadata_gen.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class MetadataGenerator {
1010
* @param {PRData} data
1111
*/
1212
constructor(data) {
13-
const { owner, repo, pr, reviewers, argv } = data;
13+
const { owner, repo, pr, reviewers, argv, skipRefs } = data;
1414
this.owner = owner;
15+
this.skipRefs = skipRefs;
1516
this.repo = repo;
1617
this.pr = pr;
1718
this.reviewers = reviewers;
@@ -33,10 +34,17 @@ class MetadataGenerator {
3334
const fixes = parser.getFixes();
3435
const refs = parser.getRefs();
3536
const altPrUrl = parser.getAltPrUrl();
36-
const meta = [
37-
...fixes.map((fix) => `Fixes: ${fix}`),
38-
...refs.map((ref) => `Refs: ${ref}`)
39-
];
37+
38+
const meta = [];
39+
40+
// If there are multiple commits in a PR, we may not want to add
41+
// Fixes/Refs metadata to all of them.
42+
if (!this.skipRefs) {
43+
// Map all issues fixed by the commit(s) in this PR.
44+
meta.push(...fixes.map((fix) => `Fixes: ${fix}`));
45+
// Map all issues referenced by the commit(s) in this PR.
46+
meta.push(...refs.map((ref) => `Refs: ${ref}`));
47+
}
4048
const backport = this.argv ? this.argv.backport : undefined;
4149
if (backport) {
4250
meta.unshift(`Backport-PR-URL: ${prUrl}`);

0 commit comments

Comments
 (0)