Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ linear-release sync --issue-pattern='\b([A-Z]+-\d+)\b'
# Also matches both IDs: fix(scope): color button red DEV-123 DEV-124
```

Identifiers that do not exist in the workspace are ignored server-side, so the broad recipe is safe but can be noisy (for example, it also matches `UTF-8`). Reverting a commit whose issues were linked only through `--issue-pattern` does not un-link them, just as with the built-in subject patterns.
Identifiers that do not exist in the workspace are ignored server-side, so the broad recipe is safe but can be noisy (for example, it also matches `UTF-8`). Reverting a commit whose issues were linked only through `--issue-pattern` does not un-link them.

### Disable branch ref detection

Expand Down
10 changes: 9 additions & 1 deletion src/extractors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,19 @@ describe("extractRevertedIssueIdentifiersForCommit", () => {
expect(ids(result)).toEqual(["DRIVE-320"]);
});

it("ignores identifier in unwrapped message without magic word", () => {
it("extracts identifier from unwrapped subject prefix", () => {
const result = extractRevertedIssueIdentifiersForCommit({
sha: "abc",
message: 'Revert "DRIVE-320: Fix memory leak in background location service"',
});
expect(ids(result)).toEqual(["DRIVE-320"]);
});

it("ignores identifier in unwrapped message without magic word or subject prefix", () => {
const result = extractRevertedIssueIdentifiersForCommit({
sha: "abc",
message: 'Revert "Fix memory leak, see DRIVE-320"',
});
expect(ids(result)).toEqual([]);
});

Expand Down
14 changes: 9 additions & 5 deletions src/extractors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export function extractLinearIssueIdentifiersForCommit(

// Odd depth = revert; even depth = non-revert or revert-of-revert (re-add).
const { depth: branchDepth, inner: strippedBranch } = parseRevertBranch(commit.branchName ?? "");
const { depth: messageDepth, afterTitle } = parseRevertMessage(commit.message ?? "");
const { depth: messageDepth, inner: innerSubject, afterTitle } = parseRevertMessage(commit.message ?? "");

const found = new Map<string, ExtractedIdentifier>();

Expand Down Expand Up @@ -291,8 +291,11 @@ export function extractLinearIssueIdentifiersForCommit(
// already-shipped references to this commit.
const scanTarget = messageDepth % 2 === 1 ? afterTitle : (commit.message ?? "");
const message = stripSquashBlock(scanTarget);
// A revert of a revert re-adds the original subject's prefix (`[ENG-5] ...`),
// which only matches once the `Revert "` layers are unwrapped.
const subjectTarget = messageDepth > 0 && messageDepth % 2 === 0 ? innerSubject : message;
if (message.length > 0) {
for (const match of [...matchCommonSubjectPatterns(message), ...matchMagicWordIdentifiers(message)]) {
for (const match of [...matchCommonSubjectPatterns(subjectTarget), ...matchMagicWordIdentifiers(message)]) {
if (!found.has(match.identifier)) {
found.set(match.identifier, {
identifier: match.identifier,
Expand Down Expand Up @@ -548,11 +551,12 @@ export function extractRevertedIssueIdentifiersForCommit(commit: CommitContext):
}
}

// Use magic-word gating on the inner message, same as the add path, to avoid
// false positives from generic word-number tokens (e.g. "Bump v1-2 to v1-3").
// Match the inner subject the same way the add path matched the original
// commit: subject prefixes and magic words, not bare word-number tokens
// (e.g. "Bump v1-2 to v1-3").
if (messageDepth % 2 === 1) {
const innerStripped = stripSquashBlock(innerMessage);
for (const match of matchMagicWordIdentifiers(innerStripped)) {
for (const match of [...matchCommonSubjectPatterns(innerStripped), ...matchMagicWordIdentifiers(innerStripped)]) {
if (!found.has(match.identifier)) {
found.set(match.identifier, {
identifier: match.identifier,
Expand Down
18 changes: 18 additions & 0 deletions src/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ describe("scanCommits", () => {
});
});

describe.each(["[ENG-5] Add thing", "(ENG-5) Add thing", "ENG-5: Add thing"])("revert of %s", (subject) => {
const add = { sha: "a1", message: subject };
const revert = { sha: "r1", message: `Revert "${subject}"` };
const reAdd = { sha: "rr1", message: `Revert "Revert "${subject}""` };

it("reverts the issue", () => {
const result = scanCommits([add, revert], {});
expect(result.issueReferences).toEqual([]);
expect(result.revertedIssueReferences).toEqual([{ identifier: "ENG-5", commitSha: "r1" }]);
});

it("re-adds the issue on a revert of the revert", () => {
const result = scanCommits([add, revert, reAdd], {});
expect(result.issueReferences).toEqual([{ identifier: "ENG-5", commitSha: "rr1" }]);
expect(result.revertedIssueReferences).toEqual([]);
});
});

describe("last-write-wins edge cases", () => {
it("separates different issues into added and reverted lists", () => {
const commits: CommitContext[] = [
Expand Down
Loading