Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 15 additions & 26 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
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,30 @@
// 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 =>
const amended = original.slice(0, -originalTrailers.length).trim().split('\n');

Check failure on line 340 in lib/landing_session.js

View workflow job for this annotation

GitHub Actions / Lint using ESLint

Trailing spaces not allowed
// Only keep existing trailers that we won't add ourselves
const keptTrailers = originalTrailers.split('\n').filter(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('');
}
!REVIEW_RE.test(line));
amended.push('', ...keptTrailers);

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, ' +
`but '${line}' is present and should be a trailer.`);
process.exit(1); // make it work with git rebase -x
}
if (keptTrailers.includes(line)) {
cli.warn(`Found ${line}, skipping..`);
continue;
}

if (BACKPORT_RE.test(line)) {
const prIndex =
(amended.findIndex(datum => PR_RE.test(datum)) + 1) ||
Expand Down
2 changes: 2 additions & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default class Session {
writeJson(this.sessionPath, {
state: STARTED,
prid: this.prid,
backport: this.backport,
// Filter out getters, those are likely encrypted data we don't need on the session.
config: Object.entries(Object.getOwnPropertyDescriptors(this.config))
.reduce((pv, [key, desc]) => {
Expand Down Expand Up @@ -271,6 +272,7 @@ export default class Session {
const sess = this.session;
if (sess.prid) {
this.prid = sess.prid;
this.backport = sess.backport;
this.config = sess.config;
}
return this;
Expand Down
Loading