Skip to content

Commit

Permalink
feat: add flag to disable copying of existing reactions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSench authored Nov 6, 2024
1 parent efb9d3e commit 334d94d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The PR Channel Slackbot action does the following steps for each configured Slac
- The action adds a response within the thread for each message containing a link to an open pull request.

5. **Copy Reactions**:
- Any reactions present on the original message are copied over to the response within the thread, ensuring continuity and visibility of feedback.
- Any reactions present on the original message are copied over to the response within the thread, ensuring continuity and visibility of feedback. This can be disabled via

### Example Output
![alt text](images/example.png)
Expand Down Expand Up @@ -154,14 +154,15 @@ Example `pr_channel_slackbot_config.json`:
"limit": 100
},
"project-bar-prs": {
"channelId": "C654321"
"channelId": "C654321",
"disableReactionCopying": true
},
"project-baz-prs": {
"channelId": "C987654",
"limit": 50,
"disabled": true
}
}
},
}
```

Expand All @@ -179,13 +180,14 @@ The `reactions` section contains configuration for each reaction type used by th
The `channels` section contains a map of human-readable channel names to channel configurations. The name of the keys here does not impact processing. It is recommended that the keys match the name of the assocaited channel for clarity.

Each channel configuration can have the following fields:
1. `channelId` - (required) the ID of the channel.
* `channelId` - (required) the ID of the channel.
> [!NOTE]
> If you do not know the ID of a channel, you can easily retrieve it from a link to that channel. Simply right-click on the channel and select `Copy` > `Copy link`. The last part of the link will be the channel ID. For example, if your channel's link is `https://mycompany.slack.com/archives/C123456`, then the channel ID is `C123456`.
2. `limit` - (optional - default `50`) this limits how many messages in the channel will be reviewed for pull requests. Only the last `<limit>` messages will be checked.
* `limit` - (optional - default `50`) this limits how many messages in the channel will be reviewed for pull requests. Only the last `<limit>` messages will be checked.
> [!NOTE]
> It is recommended that you use a channel that is dedicated for pull requests to separate requests for reviews from other development-related conversations. If your team is consistently reviewing pull requests, a large limit should not be required.
3. `disabled` - (optional - default `false`) if you wish to disable a channel without completely removing it, you can mark it as disabled.
* `disabled` - (optional - default `false`) if you wish to disable a channel without completely removing it, you can mark it as disabled.
* `disableReactionCopying` - (optional - default `false`) disable copying of reactions from the original post to the threads when `true`.

## License

Expand Down
17 changes: 11 additions & 6 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42391,7 +42391,7 @@ async function run() {
}

messagesForChannel.push(
await (0,_workflow_mjs__WEBPACK_IMPORTED_MODULE_1__/* .buildPrMessage */ .wB)(channelId, message, pullRequests[0], reactionConfig)
await (0,_workflow_mjs__WEBPACK_IMPORTED_MODULE_1__/* .buildPrMessage */ .wB)(channelId, message, pullRequests[0], reactionConfig, channelConfig)
);
}
await (0,_slack_mjs__WEBPACK_IMPORTED_MODULE_2__/* .postOpenPrs */ .JZ)(channelId, messagesForChannel);
Expand Down Expand Up @@ -42560,6 +42560,7 @@ function distinct(array) {
* @typedef {Object} ChannelConfig
* @property {string} channelId
* @property {number} limit
* @property {boolean} disableReactionCopying
*/
/**
* @typedef {Object} PrMessage
Expand All @@ -42586,7 +42587,8 @@ function getConfig() {
const channelConfig = Object.values(rawChannelConfig)
.map(it => ({
...it,
limit: it.limit ?? 50
limit: it.limit ?? 50,
disableReactionCopying: it.disableReactionCopying ?? false
}))
.filter(it => it.channelId && !it.disabled);

Expand Down Expand Up @@ -42656,13 +42658,16 @@ function isResolved(message, reactionConfig) {
* @param {SlackMessage} message
* @param {PullRequest} pullRequest
* @param {ReactionConfig} reactionConfig
* @param {ChannelConfig} channelConfig
* @returns {Promise<PrMessage>}
*/
async function buildPrMessage(channelId, message, pullRequest, reactionConfig) {
async function buildPrMessage(channelId, message, pullRequest, reactionConfig, channelConfig) {
/** @type {Array<string>} */
const existingReactions = (message.reactions ?? [])
.map(reaction => reaction.name)
.filter(it => it);
const existingReactions = channelConfig.disableReactionCopying
? []
: (message.reactions ?? [])
.map(reaction => reaction.name)
.filter(it => it);
const reviewReactions = await (0,github/* getReviewReactions */.zp)(pullRequest, reactionConfig);
const allReactions = distinct([...existingReactions, ...reviewReactions]);
const permalink = await (0,slack/* getPermalink */.t5)(channelId, message.ts);
Expand Down
3 changes: 2 additions & 1 deletion example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
],
"changesRequested": [
"changes-requested"
]
],
"copyExisting": false
},
"channels": {
"project-foo-prs": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function run() {
}

messagesForChannel.push(
await buildPrMessage(channelId, message, pullRequests[0], reactionConfig)
await buildPrMessage(channelId, message, pullRequests[0], reactionConfig, channelConfig)
);
}
await postOpenPrs(channelId, messagesForChannel);
Expand Down
15 changes: 10 additions & 5 deletions src/workflow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { distinct } from './utils.mjs';
* @typedef {Object} ChannelConfig
* @property {string} channelId
* @property {number} limit
* @property {boolean} disableReactionCopying
*/
/**
* @typedef {Object} PrMessage
Expand All @@ -45,7 +46,8 @@ export function getConfig() {
const channelConfig = Object.values(rawChannelConfig)
.map(it => ({
...it,
limit: it.limit ?? 50
limit: it.limit ?? 50,
disableReactionCopying: it.disableReactionCopying ?? false
}))
.filter(it => it.channelId && !it.disabled);

Expand Down Expand Up @@ -115,13 +117,16 @@ function isResolved(message, reactionConfig) {
* @param {SlackMessage} message
* @param {PullRequest} pullRequest
* @param {ReactionConfig} reactionConfig
* @param {ChannelConfig} channelConfig
* @returns {Promise<PrMessage>}
*/
export async function buildPrMessage(channelId, message, pullRequest, reactionConfig) {
export async function buildPrMessage(channelId, message, pullRequest, reactionConfig, channelConfig) {
/** @type {Array<string>} */
const existingReactions = (message.reactions ?? [])
.map(reaction => reaction.name)
.filter(it => it);
const existingReactions = channelConfig.disableReactionCopying
? []
: (message.reactions ?? [])
.map(reaction => reaction.name)
.filter(it => it);
const reviewReactions = await getReviewReactions(pullRequest, reactionConfig);
const allReactions = distinct([...existingReactions, ...reviewReactions]);
const permalink = await getPermalink(channelId, message.ts);
Expand Down

0 comments on commit 334d94d

Please sign in to comment.