Skip to content

Commit d211508

Browse files
committed
Add NOTHING action
This is a proposal for a change that allows you to leave the `action` column blank to signify that you want the rule to match messages and stop processing further rules, but not actually move the thread from its current state (similar to the current `mark_important` column behavior). I'm having trouble correctly routing code review emails. I don't want CI messages for other people's changes to move threads to my inbox, but if I specify `archive` on those, and a CI message is processed in the same run as a relevant message, it overrides the relevant message. I could move the CI filter rule below, but that precludes a "catch-all" review rule to route uncategorized reviews to my inbox. If this seems OK, let me know and I can add tests and make it a nicer thing.
1 parent fc33708 commit d211508

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

Processor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class Processor {
3030
break;
3131
}
3232
if (rule.condition.match(message_data)) {
33-
console.log(`rule ${rule} matches message ${message_data}, apply action ${rule.thread_action}`);
33+
console.log(`Rule ${rule} matches message ${message_data}, apply action ${rule.thread_action}`);
3434
thread_data.thread_action.mergeFrom(rule.thread_action);
35+
console.log(`Thread action after merging: ${thread_data.thread_action}`)
3536
let endThread = false;
3637
switch (rule.thread_action.action_after_match) {
3738
case ActionAfterMatchType.DONE:

Rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Rule {
6565

6666
private static parseInboxActionType(str: string): InboxActionType {
6767
if (str.length === 0) {
68-
return InboxActionType.DEFAULT;
68+
return InboxActionType.NOTHING;
6969
}
7070
const result = InboxActionType[str.toUpperCase() as keyof typeof InboxActionType];
7171
assert(result !== undefined, `Can't parse inbox action value ${str}.`);

ThreadAction.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ThreadAction from './ThreadAction';
1+
import ThreadAction, { InboxActionType } from './ThreadAction';
22
import {assert} from './utils';
33

44
it('Adds parent labels', () => {
@@ -20,15 +20,24 @@ but got ${Array.from(action.label_names).join(', ')}`);
2020
it('Does not add parent labels for empty list', () => {
2121
const labels: string[] = [];
2222
const action = new ThreadAction();
23-
const expected = new Set([])
2423

2524
action.addLabels(labels);
2625

27-
assert(action.label_names.size === expected.size,
28-
`Expected ${Array.from(expected).join(', ')},
29-
but got ${Array.from(action.label_names).join(', ')}`);
26+
assert(action.label_names.size === 0,
27+
`Expected empty set, but got ${Array.from(action.label_names).join(', ')}`);
28+
});
3029

31-
for (const label of expected) {
32-
assert(action.label_names.has(label), `Expected label ${label}, but not present in action.`);
33-
}
30+
it('Correctly merges NOTHING actions', () => {
31+
const thread_data_action = new ThreadAction();
32+
const rule_action = new ThreadAction();
33+
rule_action.move_to = InboxActionType.NOTHING;
34+
35+
assert(thread_data_action.move_to == InboxActionType.DEFAULT,
36+
`move_to should be DEFAULT, but is ${thread_data_action.move_to}`);
37+
thread_data_action.mergeFrom(rule_action);
38+
39+
assert(thread_data_action.move_to == InboxActionType.NOTHING,
40+
`move_to should be NOTHING, but is ${thread_data_action.move_to}`);
41+
assert(rule_action.toString() == '>NOTHING +L',
42+
`rule_action should be '>NOTHING +L', but is ${rule_action}`);
3443
});

ThreadAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
export enum BooleanActionType {DEFAULT, ENABLE, DISABLE}
1818

19-
export enum InboxActionType {DEFAULT, INBOX, ARCHIVE, TRASH}
19+
export enum InboxActionType {DEFAULT, INBOX, ARCHIVE, TRASH, NOTHING}
2020

2121
export enum ActionAfterMatchType {DEFAULT, DONE, FINISH_STAGE, NEXT_STAGE}
2222

ThreadData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ export class ThreadData {
121121
}
122122

123123
validateActions() {
124-
if (!this.thread_action.hasAnyAction()) {
124+
if (!this.thread_action.hasAnyAction() && this.thread_action.move_to != InboxActionType.NOTHING) {
125125
const messages = this.raw.getMessages();
126126
const last_message = messages[messages.length - 1];
127127
const from = last_message.getFrom();
128128
const to = last_message.getTo();
129-
throw `Thread "${this.raw.getFirstMessageSubject()}" from ${from} to ${to} has no action, does it match any rule?`;
129+
throw `Thread "${this.raw.getFirstMessageSubject()}" from ${from} to ${to} has default action (${this.thread_action}), does it match any rule?`;
130130
}
131131
}
132132

133133
static applyAllActions(session_data: SessionData, all_thread_data: ThreadData[]) {
134134
const label_action_map: { [key: string]: GoogleAppsScript.Gmail.GmailThread[] } = {};
135135
const moving_action_map = new Map<InboxActionType, GoogleAppsScript.Gmail.GmailThread[]>([
136-
[InboxActionType.DEFAULT, []], [InboxActionType.INBOX, []], [InboxActionType.ARCHIVE, []], [InboxActionType.TRASH, []]
136+
[InboxActionType.DEFAULT, []], [InboxActionType.INBOX, []], [InboxActionType.ARCHIVE, []], [InboxActionType.TRASH, []], [InboxActionType.NOTHING, []]
137137
]);
138138
const important_action_map = new Map<BooleanActionType, GoogleAppsScript.Gmail.GmailThread[]>([
139139
[BooleanActionType.DEFAULT, []], [BooleanActionType.ENABLE, []], [BooleanActionType.DISABLE, []]

0 commit comments

Comments
 (0)