Skip to content

Commit

Permalink
Merge pull request #10 from BottlecapDave/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
BottlecapDave authored Jul 12, 2023
2 parents 80b1ef2 + 49632a9 commit 57fc47c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitLab Merge Request Reminder

![Docker Image Version (latest semver)](https://img.shields.io/docker/v/bottlecapdave/gitlab-merge-request-reminder) [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/bottlecapdave)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/bottlecapdave/gitlab-merge-request-reminder)](https://hub.docker.com/r/bottlecapdave/gitlab-merge-request-reminder) [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/bottlecapdave)

Sends a notification to a Slack webhook highlighting open merge requests for a given GitLab repository. If no merge requests are open, then no notification will be sent.

Expand All @@ -14,12 +14,13 @@ Sends a notification to a Slack webhook highlighting open merge requests for a g
| INCLUDE_WIP | Determines if work in progress merge requests should be included. This is true by default. | `true` or `false` |
| INCLUDE_DRAFT | Determines if draft merge requests should be included. This is true by default. | `true` or `false` |
| GITLAB_MANDATORY_LABELS | The labels that merge requests must have assigned to them. All labels must be present. This should be comma separated (e.g. mandatory-label-1,mandatory-label-2) | `mandatory-label-1,mandatory-label-2` |
| GITLAB_EXCLUDED_LABELS | The labels that merge requests must not have assigned to them. Any label must be present for the merge request to be ignored. This should be comma separated (e.g. excluded-label-1,excluded-label-2) | `excluded-label-1,excluded-label-2` |
| SLACK_WEBHOOK_URL | The URL of the slack incoming webhook to send the notification to. | |
| SLACK_TARGET | The target of the slack message. This is `@here` by default. | `@here` |

## Docker

This is available as a docker image, available on [docker hub](https://hub.docker.com/repository/docker/bottlecapdave/gitlab-merge-request-reminder).
This is available as a docker image, available on [docker hub](https://hub.docker.com/r/bottlecapdave/gitlab-merge-request-reminder).

## Example Uses

Expand All @@ -32,7 +33,7 @@ You could create a gitlab job which is run on a [schedule](https://docs.gitlab.c
```
merge-request-reminder:
stage: notify
image: bottlecapdave/gitlab-merge-request-reminder:v1.0.0
image: bottlecapdave/gitlab-merge-request-reminder:v1.5.0
only:
refs:
- schedules
Expand Down
31 changes: 31 additions & 0 deletions reminder/src/gitlabService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function createRequestData(): IGitlabMergeRequestRequest {
includeWorkInProgress: true,
projectIds: [process.env.TEST_PROJECT_ID as string],
mandatoryLabels: [],
excludedLabels: [],
}
}

Expand Down Expand Up @@ -146,4 +147,34 @@ describe('GitlabService', () => {
assertMergeRequest(mergeRequests[0]);
expect(mergeRequests[0].title).toEqual('Merge request with mandatory labels');
})

test('when excluded label is specified but not present, then merge requests are returned', async () => {
const accessToken = getAccessToken();
const request: IGitlabMergeRequestRequest = {
...createRequestData(),
excludedLabels: ['non-existent']
};
const service = new GitlabService();

const mergeRequests = await service.getMergeRequests(accessToken, request);

assertMergeRequests(mergeRequests, request.includeWorkInProgress, request.includeDraft);
})

test('when excluded label is specified, then only merge requests without the excluded labels are returned', async () => {
const accessToken = getAccessToken();
const request: IGitlabMergeRequestRequest = {
...createRequestData(),
excludedLabels: ['test-label']
};
const service = new GitlabService();

const mergeRequests = await service.getMergeRequests(accessToken, request);

for (const mergeRequest of mergeRequests) {
for (const excludedLabel of request.excludedLabels) {
expect(mergeRequest.labels.includes(excludedLabel)).toEqual(false);
}
}
})
})
12 changes: 12 additions & 0 deletions reminder/src/gitlabService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IGitlabMergeRequestRequest {
includeWorkInProgress: boolean;
includeDraft: boolean;
mandatoryLabels: string[];
excludedLabels: string[];
gitlabBaseURL: string;
}

Expand Down Expand Up @@ -61,6 +62,17 @@ export class GitlabService {

return true;
})
.filter(mr => {
if (request.excludedLabels.length > 0) {
for (const excludedLabel of request.excludedLabels) {
if (mr.labels.includes(excludedLabel)) {
return false;
}
}
}

return true;
})
.map(mr => { return { ...mr, project } }));
}

Expand Down
1 change: 1 addition & 0 deletions reminder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function run() {
includeWorkInProgress: process.env.INCLUDE_WIP?.trim() !== "false",
includeDraft: process.env.INCLUDE_DRAFT?.trim() !== "false",
mandatoryLabels: (process.env.GITLAB_MANDATORY_LABELS?.trim() || "").split(','),
excludedLabels: (process.env.GITLAB_EXCLUDED_LABELS?.trim() || "").split(','),
slack: {
webhookUrl: process.env.SLACK_WEBHOOK_URL?.trim() as string,
target: process.env.SLACK_TARGET?.trim() as string || '@here'
Expand Down

0 comments on commit 57fc47c

Please sign in to comment.