Merged
Conversation
aa8cd32 to
23accde
Compare
Owner
Author
|
@copilot PTLA |
There was a problem hiding this comment.
Pull request overview
This PR refactors Ukko’s label assignment logic into a config-driven rules engine, and updates local/dev tooling, CI, docs, and tests to match the new approach.
Changes:
- Introduce
RULES+HANDLERSconfiguration inmodules/ukko.jsand updategetLabelsto evaluate rules generically. - Expand mocha coverage to validate the config-driven engine behavior and exports.
- Update local run entrypoint (
app.js+npm start), add a Makefile for common tasks, and adjust GitHub Actions workflow to use containerized Node environments.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
modules/ukko.js |
Adds RULES/HANDLERS config and rewrites label matching to use the rule engine. |
test/ukko.test.js |
Adds tests targeting the config-driven engine and new exports. |
app.js |
Prevents runUkko() from executing when imported (e.g., by tests). |
README.md |
Updates run instructions and documents the new config-driven rules model. |
package.json |
Updates start to run node app.js. |
package-lock.json |
Updates lockfile to v3 format (npm 7+). |
Makefile |
Adds install/test/lint/shell convenience targets (optionally via container engine). |
.github/workflows/node.js.yml |
Switches CI to run in Node containers and invokes Makefile targets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+19
to
+28
| node-version: [18-alpine, 20-alpine, 22-alpine] | ||
|
|
||
| container: | ||
| image: node:${{ matrix.node-version }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm install | ||
| - run: npm test | ||
| - run: npm run lint | ||
| - uses: actions/checkout@v4 | ||
| - run: apk add --no-cache make | ||
| - run: make install | ||
| - run: make test |
Makefile
Outdated
Comment on lines
+5
to
+32
| CONTAINER_ENGINE := $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null) | ||
|
|
||
| .PHONY: shell test lint install clean | ||
|
|
||
| install: | ||
| ifdef CONTAINER_ENGINE | ||
| $(CONTAINER_ENGINE) run --rm -v $(PWD):$(WORKDIR):Z -w $(WORKDIR) $(IMAGE) npm install | ||
| else | ||
| npm install | ||
| endif | ||
|
|
||
| test: | ||
| ifdef CONTAINER_ENGINE | ||
| $(CONTAINER_ENGINE) run --rm -v $(PWD):$(WORKDIR):Z -w $(WORKDIR) $(IMAGE) npx mocha | ||
| else | ||
| npx mocha | ||
| endif | ||
|
|
||
| lint: | ||
| ifdef CONTAINER_ENGINE | ||
| $(CONTAINER_ENGINE) run --rm -v $(PWD):$(WORKDIR):Z -w $(WORKDIR) $(IMAGE) npx eslint . | ||
| else | ||
| npx eslint . | ||
| endif | ||
|
|
||
| shell: | ||
| ifdef CONTAINER_ENGINE | ||
| $(CONTAINER_ENGINE) run --rm -it -v $(PWD):$(WORKDIR):Z -w $(WORKDIR) $(IMAGE) sh |
test/ukko.test.js
Outdated
Comment on lines
+229
to
+237
| // This test requires an endswith rule to exist in RULES | ||
| // Find any endswith rule and test it | ||
| const endsWithRule = RULES.find(r => r.endswith) | ||
| if (endsWithRule) { | ||
| // construct a header value that ends with the suffix | ||
| const headers = { [endsWithRule.header]: `Test User <test${endsWithRule.endswith}` } | ||
| const message = new GmailMessage(headers) | ||
| const result = getLabels(message) | ||
| expect(result.length).to.be.greaterThan(0) |
test/ukko.test.js
Outdated
Comment on lines
+256
to
+272
| // Find a fallback rule that matches on From | ||
| const fallbackRule = RULES.find(r => r.fallback && r.header === 'From') | ||
| if (fallbackRule) { | ||
| // construct headers that match both a non-fallback rule AND the fallback | ||
| const headers = { | ||
| From: 'Github <noreply@github.com>' | ||
| } | ||
| // only add fallback match if it wouldn't conflict | ||
| if (fallbackRule.contains && !headers.From.includes(fallbackRule.contains)) { | ||
| // skip — can't test this combination with github | ||
| } else { | ||
| const message = new GmailMessage(headers) | ||
| const result = getLabels(message) | ||
| // should have github label but not the fallback label | ||
| expect(result).to.include('github') | ||
| } | ||
| } |
modules/ukko.js
Outdated
Comment on lines
+123
to
+129
| if (email && email.includes('@') && email.includes('.')) { | ||
| const fqdn = email.split('@')[1] | ||
| messageFromDomain = fqdn.split('.').reverse()[1] | ||
| } | ||
| const listIDshort = getReMatch('listid', message.getHeader('List-Id')) | ||
| let label = baseLabel + '/' + listIDshort | ||
| if (messageFromDomain !== 'mydomain') { |
Replaces hardcoded if/else label logic in getLabels() with a
declarative RULES array and HANDLERS object pattern.
- RULES: array of {header, contains/endswith, label, handler, fallback}
- HANDLERS: named functions receiving (message, baseLabel) for dynamic sublabeling
- Fallback rules only fire when no other rules matched
- Added Makefile for containerized testing (node:20-alpine via Podman)
- 19 new tests (38 total), all passing
- Lint clean (0 errors)
- Updated README with config-driven documentation
- Fixed npm start: node app.js instead of node .
Closes #1
23accde to
ee1ce47
Compare
Owner
Author
|
@copilot resolve addressed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces hardcoded if/else label logic in getLabels() with a declarative RULES array and HANDLERS object pattern.
Closes #1