Skip to content
Open
Changes from all commits
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
38 changes: 14 additions & 24 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export default class LandingSession extends Session {
const BACKPORT_RE = /^BACKPORT-PR-URL\s*:\s*(\S+)$/i;
const PR_RE = /^PR-URL\s*:\s*(\S+)$/i;
const REVIEW_RE = /^Reviewed-By\s*:\s*(\S+)$/i;
const CVE_RE = /^CVE-ID\s*:\s*(\S+)$/i;
const CVE_RE = /^CVE-ID\s*:\s*(\S+)$/im;

this.startAmending();

Expand All @@ -328,41 +328,31 @@ export default class LandingSession extends Session {
// git has very specific rules about what is a trailer and what is not.
// Instead of trying to implement those ourselves, let git parse the
// original commit message and see if it outputs any trailers.
const originalHasTrailers = runSync('git', [
const originalTrailers = runSync('git', [
'interpret-trailers', '--parse', '--no-divider'
], {
input: `${original}\n`
}).trim().length !== 0;
});
const containCVETrailer = CVE_RE.test(originalTrailers);

const metadata = this.metadata.trim().split('\n');
// Filtering out metadata that we will add ourselves:
const isFiltered = line =>
// Only keep existing trailers that we won't add ourselves
const shouldKeepTrailer = line =>
!!line &&
(!PR_RE.test(line) || this.backport) &&
!BACKPORT_RE.test(line) &&
!REVIEW_RE.test(line);
const amended = original.split('\n').filter(isFiltered);

// If the original commit message already contains trailers (such as
// "Co-authored-by"), we simply add our own metadata after those. Otherwise,
// we have to add an empty line so that git recognizes our own metadata as
// trailers in the amended commit message.
if (!originalHasTrailers) {
amended.push('');
}
const amended = original.slice(0, -originalTrailers.length).trim().split('\n');

amended.push('', ...originalTrailers.split('\n').filter(shouldKeepTrailer));

let containCVETrailer = false;
for (const line of metadata) {
if (line.length !== 0 && original.includes(line) && !isFiltered(line)) {
containCVETrailer ||= CVE_RE.test(line);
if (originalHasTrailers) {
cli.warn(`Found ${line}, skipping..`);
continue;
} else {
cli.error('Git found no trailers in the original commit message, ' +
if (originalTrailers.includes(line)) {
cli.error('Git found no trailers in the original commit message, ' +
`but '${line}' is present and should be a trailer.`);
process.exit(1); // make it work with git rebase -x
}
process.exit(1); // make it work with git rebase -x
}

if (BACKPORT_RE.test(line)) {
const prIndex =
(amended.findIndex(datum => PR_RE.test(datum)) + 1) ||
Expand Down
Loading