Skip to content
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ It uses GitHub webhooks to scale across repositories without needing to add a Gi

GitHub apps are used for authentication to limit the required permissions.

## Configuration

The app can be configured with a `.github/comment-ops.yml` file in the main branch of the repository.

This can also be applied organization wide by creating it in the organization's `.github` repository.

The order of configuration is:

`default config` -> `organization` -> `repository`

Default configuration:

```yaml
commands:
label:
allowedLabels: [] # any label is allowed
enabled: true
removeLabel:
allowedLabels: [] # any label is allowed
enabled: true
reopen:
enabled: true
reviewer:
enabled: true
transfer:
enabled: true
```

## Getting started

First you will need to create a GitHub app. Add the permissions required for the commands you are using (see next section), and tick "Subscribe to events" > "Issue comment"
Expand Down
87 changes: 87 additions & 0 deletions app/command-enabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const enabled = {
enabled: true,
};

function notEnabled(command) {
return {
enabled: false,
error: `The \`${command}\` is not enabled for this repository`,
};
}

export function transferEnabled(config) {
if (!config.commands.transfer.enabled) {
return notEnabled("transfer");
}

return enabled;
}

export function labelEnabled(config, labels) {
const labelConfig = config.commands.label;

if (!labelConfig.enabled) {
return notEnabled("label");
}

if (
// if length is = 0 then all labels are allowed
labelConfig.allowedLabels.length > 0 &&
!labels.every((label) => labelConfig.allowedLabels.includes(label))
) {
return {
enabled: false,
error: `${labels} doesn't match the allowed labels \`${labelConfig.allowedLabels.join(
","
)}\``,
};
}

return enabled;
}

export function closeEnabled(config) {
if (!config.commands.close.enabled) {
return notEnabled("close");
}

return enabled;
}

export function reopenEnabled(config) {
if (!config.commands.reopen.enabled) {
return notEnabled("reopen");
}

return enabled;
}

export function removeLabelEnabled(config, labels) {
const labelConfig = config.commands.removeLabel;
if (!labelConfig.enabled) {
return notEnabled("remove-label");
}

if (
// if length is = 0 then all labels are allowed
labelConfig.allowedLabels.length > 0 &&
!labels.every((label) => labelConfig.allowedLabels.includes(label))
) {
return {
enabled: false,
error: `${labels} doesn't match the allowed labels \`${labelConfig.allowedLabels.join(
","
)}\``,
};
}

return enabled;
}

export function reviewerEnabled(config) {
if (!config.commands.reviewer.enabled) {
return notEnabled("reviewer");
}

return enabled;
}
Loading