Skip to content

Commit

Permalink
Merge pull request #6 from BottlecapDave/develop
Browse files Browse the repository at this point in the history
merge develop in main
  • Loading branch information
BottlecapDave authored Feb 19, 2022
2 parents 47e296e + 5bfdbb7 commit 68506a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 3 additions & 4 deletions .cz-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var scopes = [
'api-client',
'sensor',
'binary-sensor',
'config'
'gitlab',
'slack',
'docker'
]

module.exports = {
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Sends a notification to a Slack webhook highlighting open merge requests for a g

| Variable | Details | Example Values |
| -------------------- | --------------------------------------------------------------------------------- | -------------- |
| GITLAB_URL | The URL of the Gitlab server. Defaults to `https://gitlab.com` | `https://gitlab.company.com` |
| GITLAB_ACCESS_TOKEN | The access token for the GitLab repository. This needs at least `read_api` access and be done by following the [Gitlab instructions](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html). | |
| GITLAB_PROJECT_IDS | The GitLab project ids the merge requests are for. This should be comma separated (e.g. 12345,678910) | `12345,678910` |
| INCLUDE_WIP | Determines if work in progress merge requests should be included. This is true by default. | `true` or `false` |
Expand All @@ -15,6 +16,8 @@ Sends a notification to a Slack webhook highlighting open merge requests for a g

## Docker

![Docker Image Version (latest semver)](https://img.shields.io/docker/v/bottlecapdave/gitlab-merge-request-reminder)

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

## Example Uses
Expand Down
7 changes: 4 additions & 3 deletions reminder/src/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IGitlabMergeRequestRequest {
projectIds: string[];
includeWorkInProgress: boolean;
includeDraft: boolean;
gitlabBaseURL: string;
}

export namespace Gitlab {
Expand All @@ -32,14 +33,14 @@ export namespace Gitlab {

const allRequests: IGitlabMergeRequest[] = [];
for (const projectId of request.projectIds) {
const projectResp = await axios.get(`https://gitlab.com/api/v4/projects/${projectId}`, requestConfig);
const projectResp = await axios.get(`${request.gitlabBaseURL}/api/v4/projects/${projectId}`, requestConfig);
if (projectResp.status === 404) {
throw new Error(`Failed to find project '${projectId}'`);
}

const project = projectResp.data;
const resp = await axios.get(`https://gitlab.com/api/v4/projects/${projectId}/merge_requests?state=opened&scope=all&sort=asc`, requestConfig);
const resp = await axios.get(`${request.gitlabBaseURL}/api/v4/projects/${projectId}/merge_requests?state=opened&scope=all&sort=asc`, requestConfig);

const mergeRequests: IGitlabMergeRequest[] = resp.data || [];
allRequests.push(...mergeRequests.filter(mr => request.includeWorkInProgress || mr.title.startsWith("WIP:") === false)
.filter(mr => request.includeDraft || mr.title.startsWith("Draft:") === false)
Expand Down
1 change: 1 addition & 0 deletions reminder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { sendReminder, IReminderRequest } from "./service";
async function run() {
var config: IReminderRequest = {
gitlabAccessToken: process.env.GITLAB_ACCESS_TOKEN?.trim() as string,
gitlabBaseURL: process.env.GITLAB_URL?.trim() as string || "https://gitlab.com",
projectIds: (process.env.GITLAB_PROJECT_IDS?.trim() || "").split(','),
includeWorkInProgress: process.env.INCLUDE_WIP?.trim() !== "false",
includeDraft: process.env.INCLUDE_DRAFT?.trim() !== "false",
Expand Down

0 comments on commit 68506a1

Please sign in to comment.