Files
Bubberstation/tools/pull_request_hooks/autoLabel.test.js
MrMelbert a6e33ed6ac Moves PR Labeling from webhook processor to Github actions (#89190)
## About The Pull Request

Strips auto-labeling behavior from the webhook processor to an action.
All that remains in the webhook processor is ingame PR announcements,
"changelog validation" (which is either broken or we have disabled), and
handling for "request review" (which we have disabled)

Keywords have been maintained 1:1, unless I missed something or
accidentally shoved something where it shouldn't be

I wanted to link this to the changelog parser but that seems like a
slightly larger project so I'll just throw this up as-is

Note: I'm not very experienced in writing actions so review with
scrutiny

## Why

Actions are a lot easier to maintain and set up for downstreams

Adding new labels should now be like, 10x easier since all you need to
do is slap it in the config file

Webhook processor is also kinda old an breaks semi-frequently

### (Tested)


![image](https://github.com/user-attachments/assets/7fe50ca7-3b18-4d6c-abcf-58c9195380bd)


![image](https://github.com/user-attachments/assets/c1643a27-27c6-420e-b6e5-355a450b0ab3)
2025-01-27 20:53:31 -07:00

45 lines
1.3 KiB
JavaScript

import { strict as assert } from "node:assert";
import { get_updated_label_set } from "./autoLabel.js";
const empty_pr = {
action: "opened",
pull_request: {
body: "This PR will have no labels",
title: "Pr with no labels",
mergeable: true,
},
};
const empty_label_set = await get_updated_label_set({ github: null, context: { payload: empty_pr } });
assert.equal(empty_label_set.length, 0, "No labels should be added");
const cl = `
My Awesome PR
:cl: Awesome Dude
add: Adds Awesome Stuff
refactor: refactored some code
:/cl:
`
const cl_pr = {
action: "opened",
pull_request: {
body: cl,
title: "Awesome PR",
mergeable: false,
},
};
const cl_label_set = await get_updated_label_set({ github: null, context: { payload: cl_pr } });
assert.ok(cl_label_set.includes("Merge Conflict"), "Merge Conflict label should be added");
assert.ok(cl_label_set.includes("Feature"), "Feature label should be added");
assert.ok(!cl_label_set.includes("Refactor"), "Refactor label should not be added");
const title_pr = {
action: "opened",
pull_request: {
title: "Logging is important",
mergeable: true,
},
};
const title_label_set = await get_updated_label_set({ github: null, context: { payload: title_pr } });
assert.ok(title_label_set.includes("Logging"), "Logging label should be added");