Skip to content

Commit 842101a

Browse files
committed
Remove some dead code for a missing metadata.pullRequestURL
In the parent of this commit, it was noticed that there is now always a `pullRequestURL`. So let's remove all code blocks that try to deal with it not being set, and make all conditional blocks that do test for its presence non-conditional. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 662688d commit 842101a

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

lib/patch-series.ts

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -608,31 +608,29 @@ export class PatchSeries {
608608
const midMatch = mails[0].match(/\nMessage-ID: <(.*)>/i);
609609
let coverMid = midMatch ? midMatch[1] : undefined;
610610

611-
if (this.metadata.pullRequestURL) {
612-
if (!coverMid) {
613-
throw new Error("Could not extract cover letter Message-ID");
614-
}
615-
const mid = coverMid;
616-
617-
const tsMatch = coverMid.match(/cover\.([0-9]+)\./);
618-
const timeStamp = tsMatch ? tsMatch[1] : `${Date.now()}`;
619-
const emailMatch = thisAuthor.match(/<(.*)>/);
620-
if (!emailMatch) {
621-
throw new Error(`Could not parse email of '${thisAuthor}`);
622-
}
623-
const email = emailMatch[1];
624-
625-
const prMatch = this.metadata.pullRequestURL.match(/\/([^/]+)\/([^/]+)\/pull\/(\d+)$/);
626-
if (prMatch) {
627-
const infix = this.metadata.iteration > 1 ? `.v${this.metadata.iteration}` : "";
628-
const repoInfix = prMatch[1] === this.config.repo.owner ? prMatch[2] : `${prMatch[1]}.${prMatch[2]}`;
629-
const newCoverMid = `pull.${prMatch[3]}${infix}.${repoInfix}.${timeStamp}.${email}`;
630-
mails.map((value: string, index: number): void => {
631-
// cheap replace-all
632-
mails[index] = value.split(mid).join(newCoverMid);
633-
});
634-
coverMid = newCoverMid;
635-
}
611+
if (!coverMid) {
612+
throw new Error("Could not extract cover letter Message-ID");
613+
}
614+
const originalCoverMid = coverMid;
615+
616+
const tsMatch = coverMid.match(/cover\.([0-9]+)\./);
617+
const timeStamp = tsMatch ? tsMatch[1] : `${Date.now()}`;
618+
const emailMatch = thisAuthor.match(/<(.*)>/);
619+
if (!emailMatch) {
620+
throw new Error(`Could not parse email of '${thisAuthor}`);
621+
}
622+
const email = emailMatch[1];
623+
624+
const prMatch = this.metadata.pullRequestURL.match(/\/([^/]+)\/([^/]+)\/pull\/(\d+)$/);
625+
if (prMatch) {
626+
const infix = this.metadata.iteration > 1 ? `.v${this.metadata.iteration}` : "";
627+
const repoInfix = prMatch[1] === this.config.repo.owner ? prMatch[2] : `${prMatch[1]}.${prMatch[2]}`;
628+
const newCoverMid = `pull.${prMatch[3]}${infix}.${repoInfix}.${timeStamp}.${email}`;
629+
mails.map((value: string, index: number): void => {
630+
// cheap replace-all
631+
mails[index] = value.split(originalCoverMid).join(newCoverMid);
632+
});
633+
coverMid = newCoverMid;
636634
}
637635
this.metadata.coverLetterMessageId = coverMid;
638636

@@ -643,15 +641,10 @@ export class PatchSeries {
643641
this.project.midUrlPrefix,
644642
this.metadata.referencesMessageIds,
645643
);
646-
let tagName: string | undefined;
647-
if (!this.metadata.pullRequestURL) {
648-
tagName = `${this.project.headCommit}-v${this.metadata.iteration}`;
649-
} else {
650-
const prKey = getPullRequestKeyFromURL(this.metadata.pullRequestURL);
651-
const branch = this.metadata.headLabel.replace(/:/g, "/");
652-
const tagPrefix = prKey.owner === this.config.repo.owner ? "pr-" : `pr-${prKey.owner}-`;
653-
tagName = `${tagPrefix}${prKey.pull_number}/${branch}-v${this.metadata.iteration}`;
654-
}
644+
const prKey = getPullRequestKeyFromURL(this.metadata.pullRequestURL);
645+
const branch = this.metadata.headLabel.replace(/:/g, "/");
646+
const tagPrefix = prKey.owner === this.config.repo.owner ? "pr-" : `pr-${prKey.owner}-`;
647+
const tagName = `${tagPrefix}${prKey.pull_number}/${branch}-v${this.metadata.iteration}`;
655648

656649
this.metadata.latestTag = tagName;
657650

@@ -794,7 +787,7 @@ export class PatchSeries {
794787
firstPatchLine,
795788
} as IMailMetadata;
796789
await this.notes.set(mid, mailMeta, true);
797-
if (globalOptions && originalCommit && this.metadata.pullRequestURL) {
790+
if (globalOptions && originalCommit) {
798791
if (!globalOptions.activeMessageIDs) {
799792
globalOptions.activeMessageIDs = {};
800793
}
@@ -807,7 +800,7 @@ export class PatchSeries {
807800
}
808801
}
809802

810-
if (globalOptions && this.metadata.pullRequestURL) {
803+
if (globalOptions) {
811804
if (!globalOptions.openPRs) {
812805
globalOptions.openPRs = {};
813806
}
@@ -816,7 +809,7 @@ export class PatchSeries {
816809
}
817810

818811
if (!this.options.dryRun) {
819-
const key = this.metadata.pullRequestURL || this.project.headCommit;
812+
const key = this.metadata.pullRequestURL;
820813
await this.notes.set(key, this.metadata, true);
821814
}
822815

0 commit comments

Comments
 (0)