From 3c65495f1272f8424c6138b5d75d8e3e6d625b87 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Thu, 4 Jul 2019 23:46:31 +0000 Subject: [PATCH 1/7] chore: Update Node.js to v12.6.0 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 68309c68..b74c0245 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12.5.0-alpine as node +FROM node:12.6.0-alpine as node RUN mkdir -p /src/app WORKDIR /src/app COPY package.json /src/app/package.json @@ -6,7 +6,7 @@ RUN npm install COPY . /src/app RUN npm run build -FROM node:12.5.0-alpine +FROM node:12.6.0-alpine RUN mkdir -p /app COPY package.json /app/package.json WORKDIR /app From 9c87a469b8a42c6bd5471c2d002e8fbae468135a Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 8 Jul 2019 22:35:23 +0000 Subject: [PATCH 2/7] chore: Update dependency typescript to v3.5.3 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index e125349f..0853f1f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19520,9 +19520,9 @@ "dev": true }, "typescript": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz", - "integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz", + "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==", "dev": true }, "uc.micro": { diff --git a/package.json b/package.json index 82c73c23..24542f5f 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "tsconfig-paths": "3.8.0", "tslint": "5.18.0", "typedoc": "0.14.2", - "typescript": "3.5.2", + "typescript": "3.5.3", "vuepress": "1.0.1", "vuetify": "1.5.16" }, From 32ccbeda6281adceee6ea9b4ed252f4e1d29ba97 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 10 Jul 2019 09:47:16 +0000 Subject: [PATCH 3/7] chore: Update nest monorepo to v6.5.2 --- package-lock.json | 36 ++++++++++++++++++------------------ package.json | 12 ++++++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 610bfaf7..fe402e5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2157,9 +2157,9 @@ } }, "@nestjs/common": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-6.4.1.tgz", - "integrity": "sha512-qgex1F+ag5/8rxgsBHyXjNIyNJhNGjB1UHcFhMjGYxbfaz/5TSiv5A07IN2ZkCyNPRe35YPEvM5tJjTDul6FIg==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-6.5.2.tgz", + "integrity": "sha512-vkB6JLPPckjS35usLMV3Q6vljkgzhN3jgQ+U1VY6cKriyjnkIcUKo37tNQSPYkaAGe1pOLK4IkmwMTSyhNieyg==", "requires": { "axios": "0.19.0", "cli-color": "1.4.0", @@ -2199,9 +2199,9 @@ } }, "@nestjs/core": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-6.4.1.tgz", - "integrity": "sha512-g11VtXwXtTO9i1o+is5JNhUsiUa/tNqmtW2GWxXZcmjxNbCLOOjkLd2FHsyCLpBnl7OVkYDqwL9Fcl9ydgQa3Q==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-6.5.2.tgz", + "integrity": "sha512-LTRCl4oaFP43DcPHbvVO0sH72M+N0uGwnqc0UxhJ7ovJMX6xhahSot1QTkBb56V2AIfmzaRbGpuA4qhIgBXj6A==", "requires": { "@nuxtjs/opencollective": "0.2.2", "fast-safe-stringify": "2.0.6", @@ -2212,9 +2212,9 @@ } }, "@nestjs/microservices": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/microservices/-/microservices-6.4.1.tgz", - "integrity": "sha512-8LP+5aYbt56NzWZstGiWRI6Xpi8QSCkzoBo0l0RKWpsL33bDRngTK7SfBVR4YfjE2N2FyPYWUY5t8S+0BUS1lg==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/microservices/-/microservices-6.5.2.tgz", + "integrity": "sha512-edKXp11ma0kAUhXlkDmQ3ytHSKMbZQCyhVFRAOUdDQBhtTRXr7j9UNbMR+xBZq7KdiW09kNHFmYRACTrUsnItQ==", "requires": { "iterare": "1.2.0", "json-socket": "0.3.0", @@ -2222,9 +2222,9 @@ } }, "@nestjs/platform-express": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-6.4.1.tgz", - "integrity": "sha512-i+wCYzYhj/ZlsQAdofyLDhHnMeu3rA3IYkXbRUEoNFmo4pWVRu85vXFoq8UfNWV1bv0U9VKnY7AZP4B4yXaYhw==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-6.5.2.tgz", + "integrity": "sha512-F/y+P7IkT6xALfPZO/MwiHHVl/3rYjkD4IvNa21d4QVLnBrp3CcQztysLTWtqmHMA8T5tUeoAZSDU9MnhMlK2w==", "requires": { "body-parser": "1.19.0", "cors": "2.8.5", @@ -2403,17 +2403,17 @@ } }, "@nestjs/testing": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-6.4.1.tgz", - "integrity": "sha512-TQxTGnlKRUwL081ZvQpcwthsZMcOBlH2hGq/lN+DSPCgraqx7puRyIdi4Z70zjjAKwfZ7KUYjK0/wOYd8XhsrQ==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-6.5.2.tgz", + "integrity": "sha512-wyob7CkuCdq+NBhq78JyX5Llk4tQv2fS1jcVqhvHp96zc9RxemOMvN1GUHTXo4SNVxE+hlUV1smvcsPPsmlj8Q==", "requires": { "optional": "0.1.4" } }, "@nestjs/websockets": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@nestjs/websockets/-/websockets-6.4.1.tgz", - "integrity": "sha512-pj2itFnL2LN9HUL29YpHREHIBRisTd0U7n5FjTeKGElXyxPRX+aEa95EsQRqYAq0wKIu9EDa5rP/drGKLFah3w==", + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/@nestjs/websockets/-/websockets-6.5.2.tgz", + "integrity": "sha512-VguS7Fy3AcZS8CzuvdOxOWW+9VecGJ/AwJWbG76d0iRCsqpJu+qAoPNpo9qruB1lQ0MXYHlwGgxaTcF8PzrliQ==", "requires": { "iterare": "1.2.0" } diff --git a/package.json b/package.json index 83eaea49..9b6c1863 100644 --- a/package.json +++ b/package.json @@ -35,12 +35,12 @@ "dependencies": { "@dxdeveloperexperience/hygie-database": "0.4.2", "@dxdeveloperexperience/nest-schedule": "0.4.6", - "@nestjs/common": "6.4.1", - "@nestjs/core": "6.4.1", - "@nestjs/microservices": "6.4.1", - "@nestjs/platform-express": "6.4.1", - "@nestjs/testing": "6.4.1", - "@nestjs/websockets": "6.4.1", + "@nestjs/common": "6.5.2", + "@nestjs/core": "6.5.2", + "@nestjs/microservices": "6.5.2", + "@nestjs/platform-express": "6.5.2", + "@nestjs/testing": "6.5.2", + "@nestjs/websockets": "6.5.2", "array-flat-polyfill": "1.0.1", "class-transformer": "0.2.3", "crypto-js": "3.1.9-1", From 54369408f8d17c02b565724240b91cbf58886b1f Mon Sep 17 00:00:00 2001 From: TERRIER Bastien Date: Wed, 10 Jul 2019 14:55:06 +0200 Subject: [PATCH 4/7] docs: update readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d583abec..080cc212 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ![GitHub release](https://img.shields.io/github/release/dx-developerexperience/hygie.svg) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/dx-developerexperience/hygie.svg) [![Website](https://img.shields.io/website/https/dx-developerexperience.github.io/hygie.svg)](https://dx-developerexperience.github.io/hygie/) +[![Discord](https://img.shields.io/badge/discord-online-brightgreen.svg)](https://discord.gg/w5AE8vS) ## Motivation @@ -13,6 +14,14 @@ This [NestJs](https://docs.nestjs.com/) API expose a set of customizable Rules to automate your project's life cycle. +## Quick Getting Started + +To use our solution, just [register your application](https://dx-developerexperience.github.io/hygie/guide/registerToken.html): this will create a _webhook_ in your repository and an `Connected to Hygie!` issue, to ensure that everything worked fine. + +You can now create your configuration file to fit your needs, or continue working on your project without any changes and using our default configuration file, with our _good practices_. + +For more informations, read the [Getting Started section](https://dx-developerexperience.github.io/hygie/guide/gettingStarted.html). + ## Documentation Check-out our [documentation website](https://dx-developerexperience.github.io/hygie/) for more informations. From ae5d2fff7d2712c6a1b22ec0a03500c0913f7a9e Mon Sep 17 00:00:00 2001 From: TERRIER Bastien Date: Wed, 10 Jul 2019 15:12:34 +0200 Subject: [PATCH 5/7] fix(env-var): check if env-var exist for the incoming webhook before logging an error --- src/controllers/webhook.controller.ts | 10 +++++----- src/data_access/dataAccess.service.ts | 8 ++++++++ src/env-var/env-var.service.ts | 12 +++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/controllers/webhook.controller.ts b/src/controllers/webhook.controller.ts index 9f3beb93..6edaac45 100644 --- a/src/controllers/webhook.controller.ts +++ b/src/controllers/webhook.controller.ts @@ -51,6 +51,11 @@ export class WebhookController { ) { throw new PreconditionException(); } else { + logger.info( + `=== ${webhook.getGitType()} - ${webhook.getGitEvent()} ===`, + { project: webhook.getCloneURL(), location: 'processWebhook' }, + ); + const defaultBranch: string = webhook.getDefaultBranchName(); let rulesBranch: string = defaultBranch; if (GitEventEnum.Push === webhook.getGitEvent()) { @@ -103,11 +108,6 @@ export class WebhookController { // Set Envs Var await this.envVarService.setEnvs(remoteEnvs); - logger.info( - `=== ${webhook.getGitType()} - ${webhook.getGitEvent()} ===`, - { project: webhook.getCloneURL(), location: 'processWebhook' }, - ); - // Process incoming cron files this.scheduleService.processCronFiles(webhook); diff --git a/src/data_access/dataAccess.service.ts b/src/data_access/dataAccess.service.ts index ec454d69..3ad4bd6b 100644 --- a/src/data_access/dataAccess.service.ts +++ b/src/data_access/dataAccess.service.ts @@ -97,6 +97,14 @@ export class DataAccessService { return this.dataProvider.checkIfExist(SourceEnum.Rules, path); } + /** + * Check if EnvVar object already exist + * @param path path location (file system)/key (database)/etc + */ + checkIfEnvVarExist(path: string): Promise { + return this.dataProvider.checkIfExist(SourceEnum.EnvsVar, path); + } + /** * Connection with the dataProvider */ diff --git a/src/env-var/env-var.service.ts b/src/env-var/env-var.service.ts index a0adb87f..4f4b5688 100644 --- a/src/env-var/env-var.service.ts +++ b/src/env-var/env-var.service.ts @@ -46,11 +46,13 @@ export class EnvVarService { async setEnvs(repositoryName: string) { const path: string = `remote_envs_vars/${repositoryName}/env.yml`; try { - const data: KeyValueEnvFileInterface = await this.dataAccessService.readEnvsVar( - path, - ); - const decryptedEnv = this.decryptData(data); - this.envVarAccessor.setAllEnvVar(decryptedEnv); + if (await this.dataAccessService.checkIfEnvVarExist(path)) { + const data: KeyValueEnvFileInterface = await this.dataAccessService.readEnvsVar( + path, + ); + const decryptedEnv = this.decryptData(data); + this.envVarAccessor.setAllEnvVar(decryptedEnv); + } } catch (e) { logger.error(e, { location: 'setEnvs', project: repositoryName }); } From 2d2d74a6f444322b8576f3898bbf04c1fcb7c83e Mon Sep 17 00:00:00 2001 From: TERRIER Bastien Date: Thu, 11 Jul 2019 10:27:59 +0200 Subject: [PATCH 6/7] feat: replace mustache by handlebars (#292) --- docs/post-actions/customisablePostActions.md | 6 +- docs/post-actions/existingRunnables.md | 8 +-- docs/rules/customisableRules.md | 71 ++++++++++---------- package-lock.json | 5 -- package.json | 1 - src/runnables/commentIssue.runnable.ts | 5 +- src/runnables/commentPullRequest.runnable.ts | 5 +- src/runnables/createIssue.runnable.ts | 6 +- src/runnables/createPullRequest.runnable.ts | 19 +++--- src/runnables/createRelease.runnable.ts | 11 +-- src/runnables/createTag.runnable.ts | 7 +- src/runnables/deleteBranch.runnable.ts | 5 +- src/runnables/deleteFiles.runnable.ts | 8 +-- src/runnables/deployFolder.runnable.ts | 9 +-- src/runnables/logger.runnable.ts | 9 +-- src/runnables/mergePullRequest.runnable.ts | 17 +++-- src/runnables/sendEmail.runnable.ts | 9 +-- src/runnables/updateCommitStatus.runnable.ts | 6 +- src/runnables/updateIssue.runnable.ts | 6 +- src/runnables/updatePullRequest.runnable.ts | 13 ++-- src/runnables/webhook.runnable.ts | 45 +++++++++---- src/utils/utils.ts | 11 ++- 22 files changed, 160 insertions(+), 122 deletions(-) diff --git a/docs/post-actions/customisablePostActions.md b/docs/post-actions/customisablePostActions.md index 5535a453..e041bcec 100644 --- a/docs/post-actions/customisablePostActions.md +++ b/docs/post-actions/customisablePostActions.md @@ -50,9 +50,9 @@ constructor(private readonly myService: MyService) NestJs dependency injection will handle everything. -### _mustache_ templating +### _handlebars_ templating -If you want to allow templating (you want to!), you need to use the `render()` method provide by _mustache_. +If you want to allow templating (you want to!), you need to use the `render()` method provide by our _Utils_ class. Just have a look at the `LoggerRunnable` implementation: @@ -69,4 +69,4 @@ run(ruleResult: RuleResult, args: LoggerArgs): void { } ``` -The `render()` method need the string containing the template (in the `args` object), and the data provider: `RuleResult` which is the return by the [`validate()` rule method](../rules/customisableRules.html#validate-method). +The `render()` method need the string containing the template (in the `args` object), and the data provider: `RuleResult` which is the return by the [`validate()` rule method](../rules/customisableRules.md#validate-method). diff --git a/docs/post-actions/existingRunnables.md b/docs/post-actions/existingRunnables.md index 0e4f0fee..7a66fc00 100644 --- a/docs/post-actions/existingRunnables.md +++ b/docs/post-actions/existingRunnables.md @@ -16,7 +16,7 @@ Be sure that the rule returned the `issueNumber` property in the `RuleResult` ob ### Usage -This Post-Action only needs a string message. This string can contain _mustache_ templating. +This Post-Action only needs a string message. This string can contain _handlebars_ templating. To use the `CommentIssueRunnable`, add the `callback` on your `.rulesrc` config file. @@ -40,7 +40,7 @@ Be sure that the rule returned the `pullRequest.number` property in the `RuleRes ### Usage -This Post-Action only needs a string message. This string can contain _mustache_ templating. +This Post-Action only needs a string message. This string can contain _handlebars_ templating. To use the `CommentPullRequestRunnable`, add the `callback` on your `.rulesrc` config file. @@ -188,7 +188,7 @@ This Post-Action need two args: ::: tip If you're in an `onSuccess` or `onBoth` statement, the default value will be `info`. On the other hand, if you're in an `onError` statement, it would be `error`. ::: -- `message`: a string that can contain _mustache_ templating. +- `message`: a string that can contain _handlebars_ templating. To use the `LoggerRunnable`, simply add the `callback` on your `.rulesrc` config file. @@ -389,7 +389,7 @@ This Post-Action need the following args: - `data`: the data you want to send (`any` type) _[optional]_, - `config`: the `AxiosRequestConfig` configuration _[optional]_. -All of these parameters can contain _mustache_ templating. +All of these parameters can contain _handlebars_ templating. To use the `WebhookRunnable`, simply add the `callback` on your `.rulesrc` config file. diff --git a/docs/rules/customisableRules.md b/docs/rules/customisableRules.md index 62aca653..ed6495b7 100644 --- a/docs/rules/customisableRules.md +++ b/docs/rules/customisableRules.md @@ -44,39 +44,36 @@ The following properties are all needed : These `callback`s are called sequentially and do not return value (`void` type). ::: -### Templating with _mustache_ +### Templating with _handlebars_ -Post-actions `args` support templating: **_Hygie_** use [mustache js](https://github.com/janl/mustache.js). +Post-actions `args` support templating: **_Hygie_** use [handlebars js](https://handlebarsjs.com). Consequently, you can inject data processed by the `validate()` method of the current rule (`name` attribute). You can see the [`validate()` method section](#validate-method) for more informations. For example, you can iterate over the `data.commits` array of `CommitMessageRule`, and display the commit's `sha` and the differents groups captured by the `regexp` options. -``` -'{{#data.commits}}{{sha}} = -Object: {{matches.1}} | Scope: {{matches.2}} | Issue: {{matches.3}} -{{/data.commits}}' -``` - You can also access the environment variables you've configured via the `env` prefix. More informations in the [Enviroment Variable section](./guide/useEnvVar.md). -For examples: - -``` -callback: WebhookRunnable -args: - url: 'https://webhook.site/0123-4567-89ab-cdef' - config: { - token: '{{env.API_KEY}}' - } - data: { - user: 'cron bot', - number: '{{data.number}}', - vulnerabilities: '{{{data.vulnerabilities}}}' - } +```yaml +onSuccess: + - callback: WebhookRunnable + args: + url: https://discordapp.com/api/webhooks/{{env.DISCORD_ISSUE_WEBHOOK}}/{{env.DISCORD_ISSUE_TOKEN}} + data: '{ + "embeds": [ + {{#foreach data.commits}} + { + "title": "Commit #{{sha}} = Object: {{matches.[1]}} | Scope: {{matches.[2]}} | Issue: {{matches.[3]}}", + "color": 1127128 + } + {{/foreach}} + ] + }' ``` -For more examples, check out the [documentation](https://github.com/janl/mustache.js#templates) provide by mustache. +::: tip +The `foreach` keyword has been add to solve the trailing-comma's problem. When you use it, it will add a comma at the end of the pattern, except for the last one element of the array. +::: ## Create your own rule @@ -103,23 +100,27 @@ Each Rule, have a `validate()` method as follows: export class MyCustomRule extends Rule { // ... - validate(webhook: Webhook, ruleConfig: PullRequestTitleRule): RuleResult { - const ruleResult: RuleResult = new RuleResult(webhook.getGitApiInfos()); + async validate( + webhook: Webhook, + ruleConfig: MyCustomRule, + ruleResults?: RuleResult[], + ): Promise { + const ruleResult: RuleResult = new RuleResult( + webhook.getGitApiInfos(), + webhook.getCloneURL(), + ); + this.googleAnalytics + .event('Rule', 'myCustom', webhook.getCloneURL()) + .send(); + + // BUSINESS LOGIC - /** - * Your process - * - * You can call gitApi via `this.webhook.gitService` - **/ - - // Optional - // If you want to export data for callbacks, accessible with {{data}} + ruleResult.validated = true | false; ruleResult.data = { myData: 'this is some data', myArray: ['val1', 'val2', 'val3'], }; - ruleResult.validated = true | false; - return ruleResult; + return Promise.resolve(ruleResult); } } ``` diff --git a/package-lock.json b/package-lock.json index 610bfaf7..8f7a8be0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11652,11 +11652,6 @@ "minimatch": "^3.0.0" } }, - "mustache": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mustache/-/mustache-3.0.1.tgz", - "integrity": "sha512-jFI/4UVRsRYdUbuDTKT7KzfOp7FiD5WzYmmwNwXyUVypC0xjoTL78Fqc0jHUPIvvGD+6DQSPHIt1NE7D1ArsqA==" - }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", diff --git a/package.json b/package.json index 83eaea49..5da3b8af 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "googleapis": "27.0.0", "hbs": "4.0.4", "js-yaml": "3.13.1", - "mustache": "3.0.1", "prom-client": "11.5.3", "reflect-metadata": "0.1.13", "rimraf": "2.6.3", diff --git a/src/runnables/commentIssue.runnable.ts b/src/runnables/commentIssue.runnable.ts index 556e9d6b..3c7a25fc 100644 --- a/src/runnables/commentIssue.runnable.ts +++ b/src/runnables/commentIssue.runnable.ts @@ -7,10 +7,11 @@ import { GitTypeEnum } from '../webhook/utils.enum'; import { CallbackType } from './runnables.service'; import { GitApiInfos } from '../git/gitApiInfos'; import { RunnableDecorator } from './runnable.decorator'; -import { render } from 'mustache'; + import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface CommentIssueArgs { comment: string; @@ -41,7 +42,7 @@ export class CommentIssueRunnable extends Runnable { const gitIssueInfos: GitIssueInfos = new GitIssueInfos(); gitIssueInfos.number = data.issue.number; - gitIssueInfos.comment = render(args.comment, ruleResult); + gitIssueInfos.comment = Utils.render(args.comment, ruleResult); const gitApiInfos: GitApiInfos = ruleResult.gitApiInfos; this.googleAnalytics diff --git a/src/runnables/commentPullRequest.runnable.ts b/src/runnables/commentPullRequest.runnable.ts index 68d3aa4e..f9e32ccd 100644 --- a/src/runnables/commentPullRequest.runnable.ts +++ b/src/runnables/commentPullRequest.runnable.ts @@ -7,10 +7,11 @@ import { GitCommentPRInfos } from '../git/gitPRInfos'; import { CallbackType } from './runnables.service'; import { GitApiInfos } from '../git/gitApiInfos'; import { RunnableDecorator } from './runnable.decorator'; -import { render } from 'mustache'; + import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface CommentPRArgs { comment: string; @@ -41,7 +42,7 @@ export class CommentPullRequestRunnable extends Runnable { const gitPRInfos: GitCommentPRInfos = new GitCommentPRInfos(); gitPRInfos.number = data.pullRequest.number; - gitPRInfos.comment = render(args.comment, ruleResult); + gitPRInfos.comment = Utils.render(args.comment, ruleResult); const gitApiInfos: GitApiInfos = ruleResult.gitApiInfos; this.googleAnalytics diff --git a/src/runnables/createIssue.runnable.ts b/src/runnables/createIssue.runnable.ts index 38aad3c3..ef834c32 100644 --- a/src/runnables/createIssue.runnable.ts +++ b/src/runnables/createIssue.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GithubService } from '../github/github.service'; @@ -44,14 +44,14 @@ export class CreateIssueRunnable extends Runnable { const gitApiInfos: GitApiInfos = ruleResult.gitApiInfos; const gitIssueInfos: GitIssueInfos = new GitIssueInfos(); - gitIssueInfos.title = render(args.title, ruleResult); + gitIssueInfos.title = Utils.render(args.title, ruleResult); this.googleAnalytics .event('Runnable', 'createIssue', ruleResult.projectURL) .send(); if (typeof args.description !== 'undefined') { - gitIssueInfos.description = render(args.description, ruleResult); + gitIssueInfos.description = Utils.render(args.description, ruleResult); } if (typeof args.labels !== 'undefined') { diff --git a/src/runnables/createPullRequest.runnable.ts b/src/runnables/createPullRequest.runnable.ts index 987c0f34..6c5a8b3c 100644 --- a/src/runnables/createPullRequest.runnable.ts +++ b/src/runnables/createPullRequest.runnable.ts @@ -4,13 +4,14 @@ import { GithubService } from '../github/github.service'; import { GitlabService } from '../gitlab/gitlab.service'; import { GitTypeEnum } from '../webhook/utils.enum'; import { GitPRInfos } from '../git/gitPRInfos'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { GitApiInfos } from '../git/gitApiInfos'; import { RunnableDecorator } from './runnable.decorator'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface CreatePullRequestArgs { title: string; @@ -65,24 +66,24 @@ export class CreatePullRequestRunnable extends Runnable { args.target = 'master'; } - gitCreatePRInfos.description = render(args.description, ruleResult).replace( - ///g, - '/', - ); - gitCreatePRInfos.title = render(args.title, ruleResult).replace( + gitCreatePRInfos.description = Utils.render( + args.description, + ruleResult, + ).replace(///g, '/'); + gitCreatePRInfos.title = Utils.render(args.title, ruleResult).replace( ///g, '/', ); - gitCreatePRInfos.source = render(args.source, ruleResult).replace( + gitCreatePRInfos.source = Utils.render(args.source, ruleResult).replace( ///g, '/', ); - gitCreatePRInfos.target = render(args.target, ruleResult).replace( + gitCreatePRInfos.target = Utils.render(args.target, ruleResult).replace( ///g, '/', ); if (typeof args.draft === 'string') { - gitCreatePRInfos.draft = render(args.draft, ruleResult); + gitCreatePRInfos.draft = Boolean(Utils.render(args.draft, ruleResult)); } else if (typeof args.draft === 'boolean') { gitCreatePRInfos.draft = args.draft; } diff --git a/src/runnables/createRelease.runnable.ts b/src/runnables/createRelease.runnable.ts index 8caa961f..e5752e56 100644 --- a/src/runnables/createRelease.runnable.ts +++ b/src/runnables/createRelease.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GitApiInfos } from '../git/gitApiInfos'; @@ -11,6 +11,7 @@ import { GitRelease } from '../git/gitRelease'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface CreateReleaseArgs { name: string; @@ -51,16 +52,16 @@ export class CreateReleaseRunnable extends Runnable { if (typeof args.tag === 'undefined') { return; } - gitRelease.tag = render(args.tag, ruleResult); + gitRelease.tag = Utils.render(args.tag, ruleResult); if (typeof args.name !== 'undefined') { - gitRelease.name = render(args.name, ruleResult); + gitRelease.name = Utils.render(args.name, ruleResult); } if (typeof args.description !== 'undefined') { - gitRelease.description = render(args.description, ruleResult); + gitRelease.description = Utils.render(args.description, ruleResult); } if (typeof args.ref !== 'undefined') { - gitRelease.ref = render(args.ref, ruleResult); + gitRelease.ref = Utils.render(args.ref, ruleResult); } if (gitApiInfos.git === GitTypeEnum.Github) { diff --git a/src/runnables/createTag.runnable.ts b/src/runnables/createTag.runnable.ts index 3b9b9ea5..7f33f8d3 100644 --- a/src/runnables/createTag.runnable.ts +++ b/src/runnables/createTag.runnable.ts @@ -1,9 +1,10 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { Utils } from '../rules/utils'; +import { Utils as UtilsGeneral } from '../utils/utils'; import { logger } from '../logger/logger.service'; import { GitApiInfos } from '../git/gitApiInfos'; import { GitTypeEnum } from '../webhook/utils.enum'; @@ -58,7 +59,7 @@ export class CreateTagRunnable extends Runnable { const lastSha = lastItem.sha; - const tag = render(args.tag, ruleResult); + const tag = UtilsGeneral.render(args.tag, ruleResult); const semVerRegexp = new RegExp( // tslint:disable-next-line:max-line-length @@ -74,7 +75,7 @@ export class CreateTagRunnable extends Runnable { const gitTag = new GitTag(); if (typeof args.message !== 'undefined') { - gitTag.message = render(args.message, ruleResult); + gitTag.message = UtilsGeneral.render(args.message, ruleResult); } else { gitTag.message = 'version ' + tag; } diff --git a/src/runnables/deleteBranch.runnable.ts b/src/runnables/deleteBranch.runnable.ts index 8ae15ec4..a37c84e9 100644 --- a/src/runnables/deleteBranch.runnable.ts +++ b/src/runnables/deleteBranch.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GithubService } from '../github/github.service'; @@ -10,6 +10,7 @@ import { GitTypeEnum } from '../webhook/utils.enum'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface DeleteBranchArgs { branchName?: string; @@ -51,7 +52,7 @@ export class DeleteBranchRunnable extends Runnable { ) { branchName = (ruleResult as any).data.branch; } else { - branchName = render(args.branchName, ruleResult); + branchName = Utils.render(args.branchName, ruleResult); } if (gitApiInfos.git === GitTypeEnum.Github) { diff --git a/src/runnables/deleteFiles.runnable.ts b/src/runnables/deleteFiles.runnable.ts index 3c5d9609..4ea7d354 100644 --- a/src/runnables/deleteFiles.runnable.ts +++ b/src/runnables/deleteFiles.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GithubService } from '../github/github.service'; @@ -75,7 +75,7 @@ export class DeleteFilesRunnable extends Runnable { const file: string = filesList[index]; const gitFileInfos = new GitFileInfos(); if (typeof args !== 'undefined' && typeof args.branch !== 'undefined') { - gitFileInfos.fileBranch = render(args.branch, ruleResult); + gitFileInfos.fileBranch = Utils.render(args.branch, ruleResult); } else { // Default if (typeof (ruleResult as any).data.branch !== 'undefined') { @@ -84,8 +84,8 @@ export class DeleteFilesRunnable extends Runnable { gitFileInfos.fileBranch = 'master'; } } - gitFileInfos.commitMessage = render(args.message, ruleResult); - gitFileInfos.filePath = render(file, ruleResult); + gitFileInfos.commitMessage = Utils.render(args.message, ruleResult); + gitFileInfos.filePath = Utils.render(file, ruleResult); if (gitApiInfos.git === GitTypeEnum.Github) { await this.githubService.deleteFile(gitFileInfos); diff --git a/src/runnables/deployFolder.runnable.ts b/src/runnables/deployFolder.runnable.ts index f5423588..c3bd7d72 100644 --- a/src/runnables/deployFolder.runnable.ts +++ b/src/runnables/deployFolder.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GitTypeEnum } from '../webhook/utils.enum'; @@ -11,6 +11,7 @@ import { GitRef } from '../git/gitRef'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface DeployFolderArgs { folder: string; @@ -51,11 +52,11 @@ export class DeployFolderRunnable extends Runnable { typeof args.folder !== 'undefined' && typeof args.branch !== 'undefined' ) { - const folder = render(args.folder, ruleResult); - const branch = render(args.branch, ruleResult); + const folder = Utils.render(args.folder, ruleResult); + const branch = Utils.render(args.branch, ruleResult); const message = typeof args.message !== 'undefined' - ? render(args.message, ruleResult) + ? Utils.render(args.message, ruleResult) : `deploy ${folder} to ${branch}`; const treeSha: string = await this.githubService.getTree( diff --git a/src/runnables/logger.runnable.ts b/src/runnables/logger.runnable.ts index 395c05a7..fbaef8bf 100644 --- a/src/runnables/logger.runnable.ts +++ b/src/runnables/logger.runnable.ts @@ -1,12 +1,13 @@ import { Runnable } from './runnable.class'; import { logger } from '../logger/logger.service'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface LoggerArgs { type: string; @@ -49,13 +50,13 @@ export class LoggerRunnable extends Runnable { switch (args.type) { case 'info': - logger.info(render(args.message, ruleResult)); + logger.info(Utils.render(args.message, ruleResult)); break; case 'warn': - logger.warn(render(args.message, ruleResult)); + logger.warn(Utils.render(args.message, ruleResult)); break; case 'error': - logger.error(render(args.message, ruleResult)); + logger.error(Utils.render(args.message, ruleResult)); break; } } diff --git a/src/runnables/mergePullRequest.runnable.ts b/src/runnables/mergePullRequest.runnable.ts index 1831d33d..8b70b9d9 100644 --- a/src/runnables/mergePullRequest.runnable.ts +++ b/src/runnables/mergePullRequest.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { RunnableDecorator } from './runnable.decorator'; import { GithubService } from '../github/github.service'; @@ -11,6 +11,7 @@ import { GitTypeEnum } from '../webhook/utils.enum'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface MergePullRequestArgs { commitTitle: string; @@ -54,16 +55,22 @@ export class MergePullRequestRunnable extends Runnable { if (typeof args !== 'undefined') { if (typeof args.commitMessage !== 'undefined') { - gitMergePRInfos.commitMessage = render(args.commitMessage, ruleResult); + gitMergePRInfos.commitMessage = Utils.render( + args.commitMessage, + ruleResult, + ); } if (typeof args.commitTitle !== 'undefined') { - gitMergePRInfos.commitTitle = render(args.commitTitle, ruleResult); + gitMergePRInfos.commitTitle = Utils.render( + args.commitTitle, + ruleResult, + ); } if (typeof args.sha !== 'undefined') { - gitMergePRInfos.sha = render(args.sha, ruleResult); + gitMergePRInfos.sha = Utils.render(args.sha, ruleResult); } if (typeof args.method !== 'undefined') { - switch (render(args.method.toLocaleLowerCase(), ruleResult)) { + switch (Utils.render(args.method.toLocaleLowerCase(), ruleResult)) { case 'squash': gitMergePRInfos.method = PRMethodsEnum.Squash; break; diff --git a/src/runnables/sendEmail.runnable.ts b/src/runnables/sendEmail.runnable.ts index e90b65ad..192fcec9 100644 --- a/src/runnables/sendEmail.runnable.ts +++ b/src/runnables/sendEmail.runnable.ts @@ -1,6 +1,6 @@ import { Runnable } from './runnable.class'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { readFile, writeFile } from 'fs-extra'; import { createInterface } from 'readline'; import { google } from 'googleapis'; @@ -10,6 +10,7 @@ import { RunnableDecorator } from './runnable.decorator'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; function makeBody(to: string, subject: string, message: string): string { const str = [ @@ -69,9 +70,9 @@ export class SendEmailRunnable extends Runnable { } const content = makeBody( - render(args.to, ruleResult), - render(args.subject, ruleResult), - render(args.message, ruleResult), + Utils.render(args.to, ruleResult), + Utils.render(args.subject, ruleResult), + Utils.render(args.message, ruleResult), ); gmail.users.messages.send( { diff --git a/src/runnables/updateCommitStatus.runnable.ts b/src/runnables/updateCommitStatus.runnable.ts index 713bdc07..0b9742aa 100644 --- a/src/runnables/updateCommitStatus.runnable.ts +++ b/src/runnables/updateCommitStatus.runnable.ts @@ -8,7 +8,7 @@ import { GitApiInfos } from '../git/gitApiInfos'; import { GitCommitStatusInfos } from '../git/gitCommitStatusInfos'; import { RunnableDecorator } from './runnable.decorator'; import { Utils } from '../utils/utils'; -import { render } from 'mustache'; + import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; @@ -54,14 +54,14 @@ export class UpdateCommitStatusRunnable extends Runnable { gitCommitStatusInfos.commitSha = c.sha; gitCommitStatusInfos.commitStatus = c.status; - gitCommitStatusInfos.descriptionMessage = render( + gitCommitStatusInfos.descriptionMessage = Utils.render( c.success ? Utils.getStringValue(args.successDescriptionMessage) : Utils.getStringValue(args.failDescriptionMessage), ruleResult, ); - gitCommitStatusInfos.targetUrl = render( + gitCommitStatusInfos.targetUrl = Utils.render( c.success ? Utils.getStringValue(args.successTargetUrl) : Utils.getStringValue(args.failTargetUrl), diff --git a/src/runnables/updateIssue.runnable.ts b/src/runnables/updateIssue.runnable.ts index 631153ca..2a738800 100644 --- a/src/runnables/updateIssue.runnable.ts +++ b/src/runnables/updateIssue.runnable.ts @@ -7,7 +7,7 @@ import { GitlabService } from '../gitlab/gitlab.service'; import { GitApiInfos } from '../git/gitApiInfos'; import { GitTypeEnum } from '../webhook/utils.enum'; import { IssuePRStateEnum, GitIssueInfos } from '../git/gitIssueInfos'; -import { render } from 'mustache'; + import { Utils } from '../utils/utils'; import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; @@ -61,9 +61,9 @@ export class UpdateIssueRunnable extends Runnable { if (typeof args.state !== 'undefined') { gitIssueInfos.state = - render(args.state, ruleResult).toLowerCase() === 'open' + Utils.render(args.state, ruleResult).toLowerCase() === 'open' ? IssuePRStateEnum.Open - : render(args.state, ruleResult).toLowerCase() === 'close' + : Utils.render(args.state, ruleResult).toLowerCase() === 'close' ? IssuePRStateEnum.Close : IssuePRStateEnum.Undefined; } diff --git a/src/runnables/updatePullRequest.runnable.ts b/src/runnables/updatePullRequest.runnable.ts index 3e67fa42..9aec0690 100644 --- a/src/runnables/updatePullRequest.runnable.ts +++ b/src/runnables/updatePullRequest.runnable.ts @@ -8,10 +8,11 @@ import { GitApiInfos } from '../git/gitApiInfos'; import { GitPRInfos } from '../git/gitPRInfos'; import { GitTypeEnum } from '../webhook/utils.enum'; import { IssuePRStateEnum } from '../git/gitIssueInfos'; -import { render } from 'mustache'; + import { Inject } from '@nestjs/common'; import { Visitor } from 'universal-analytics'; import { EnvVarAccessor } from '../env-var/env-var.accessor'; +import { Utils } from '../utils/utils'; interface UpdatePullRequestArgs { target: string; @@ -64,20 +65,20 @@ export class UpdatePullRequestRunnable extends Runnable { if (typeof args.state !== 'undefined') { gitPRInfos.state = - render(args.state, ruleResult).toLowerCase() === 'open' + Utils.render(args.state, ruleResult).toLowerCase() === 'open' ? IssuePRStateEnum.Open - : render(args.state, ruleResult).toLowerCase() === 'close' + : Utils.render(args.state, ruleResult).toLowerCase() === 'close' ? IssuePRStateEnum.Close : IssuePRStateEnum.Undefined; } if (typeof args.title !== 'undefined') { - gitPRInfos.title = render(args.title, ruleResult); + gitPRInfos.title = Utils.render(args.title, ruleResult); } if (typeof args.target !== 'undefined') { - gitPRInfos.target = render(args.target, ruleResult); + gitPRInfos.target = Utils.render(args.target, ruleResult); } if (typeof args.description !== 'undefined') { - gitPRInfos.description = render(args.description, ruleResult); + gitPRInfos.description = Utils.render(args.description, ruleResult); } if (gitApiInfos.git === GitTypeEnum.Github) { diff --git a/src/runnables/webhook.runnable.ts b/src/runnables/webhook.runnable.ts index d5a1a942..8535321f 100644 --- a/src/runnables/webhook.runnable.ts +++ b/src/runnables/webhook.runnable.ts @@ -1,7 +1,7 @@ import { Runnable } from './runnable.class'; import { HttpService, Inject } from '@nestjs/common'; import { RuleResult } from '../rules/ruleResult'; -import { render } from 'mustache'; + import { CallbackType } from './runnables.service'; import { logger } from '../logger/logger.service'; import { RunnableDecorator } from './runnable.decorator'; @@ -11,8 +11,8 @@ import { EnvVarAccessor } from '../env-var/env-var.accessor'; interface WebhookArgs { url: string; - data: object; - config: object; + data: object | string; + config: object | string; } /** @@ -40,16 +40,33 @@ export class WebhookRunnable extends Runnable { .event('Runnable', 'webhook', ruleResult.projectURL) .send(); - this.httpService - .post( - render(args.url, ruleResult), - render(JSON.stringify(args.data), ruleResult), - render(JSON.stringify(Utils.getObjectValue(args.config)), ruleResult), - ) - .subscribe(null, err => - logger.error(err, { - location: 'WebhookRunnable', - }), - ); + const url: string = Utils.render(args.url, ruleResult); + let config: any = {}; + let data: string; + + try { + if (typeof args.data === 'string') { + data = Utils.render(args.data, ruleResult); + } else { + data = Utils.render(JSON.stringify(args.data), ruleResult); + } + if (typeof args.config === 'string') { + config = JSON.parse(Utils.render(args.config, ruleResult)); + } else if (typeof args.config !== 'undefined') { + config = JSON.parse( + Utils.render(JSON.stringify(args.config), ruleResult), + ); + } + } catch (err) { + logger.error(err, { + location: 'WebhookRunnable', + }); + } + + this.httpService.post(url, data, config).subscribe(null, err => + logger.error(err, { + location: 'WebhookRunnable', + }), + ); } } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 3b5bf492..9a363495 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -2,15 +2,24 @@ import { GitTypeEnum } from '../webhook/utils.enum'; import 'array-flat-polyfill'; import { DataAccessService } from '../data_access/dataAccess.service'; import { GitEnv } from '../git/gitEnv.interface'; -import { render } from 'mustache'; import { logger } from '../logger/logger.service'; +import * as Handlebars from 'handlebars'; +Handlebars.registerHelper('foreach', (items, options) => { + return items.map(item => options.fn(item)).join(','); +}); + interface SplittedDirectory { base: string; name: string; } export class Utils { + static render(template, ctx) { + const handlebarsTemplate = Handlebars.compile(template); + return handlebarsTemplate(ctx); + } + /** * * @param input string x-separated or string[] From cb8fb25af6c9fc9c74a13b90b33e88f3727964bf Mon Sep 17 00:00:00 2001 From: TERRIER Bastien Date: Thu, 11 Jul 2019 10:49:51 +0200 Subject: [PATCH 7/7] fix(test): update templating syntax (#292) --- src/runnables/createPullRequest.runnable.spec.ts | 2 +- src/runnables/createTag.runnable.spec.ts | 2 +- src/runnables/deleteBranch.runnable.spec.ts | 4 ++-- src/runnables/webhook.runnable.spec.ts | 2 +- src/utils/utils.ts | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/runnables/createPullRequest.runnable.spec.ts b/src/runnables/createPullRequest.runnable.spec.ts index e80ee049..bcc37e81 100644 --- a/src/runnables/createPullRequest.runnable.spec.ts +++ b/src/runnables/createPullRequest.runnable.spec.ts @@ -45,7 +45,7 @@ describe('CreatePullRequestRunnable', () => { myGitApiInfos.git = GitTypeEnum.Undefined; args = { - title: 'WIP: {{data.branchSplit.1}}', + title: 'WIP: {{data.branchSplit.[1]}}', description: 'this is the description', }; diff --git a/src/runnables/createTag.runnable.spec.ts b/src/runnables/createTag.runnable.spec.ts index f7d8a693..f7c8f905 100644 --- a/src/runnables/createTag.runnable.spec.ts +++ b/src/runnables/createTag.runnable.spec.ts @@ -44,7 +44,7 @@ describe('CreateTagRunnable', () => { myGitApiInfos.repositoryFullName = 'bastienterrier/test_webhook'; myGitApiInfos.git = GitTypeEnum.Undefined; - args = { tag: '{{data.commits.0.matches.1}}' }; + args = { tag: '{{data.commits.[0].matches.[1]}}' }; ruleResult = new RuleResult(myGitApiInfos); ruleResult.validated = false; diff --git a/src/runnables/deleteBranch.runnable.spec.ts b/src/runnables/deleteBranch.runnable.spec.ts index 4efccde3..6adad9a5 100644 --- a/src/runnables/deleteBranch.runnable.spec.ts +++ b/src/runnables/deleteBranch.runnable.spec.ts @@ -79,7 +79,7 @@ describe('DeleteBranchRunnable', () => { .run(CallbackType.Both, ruleResultBranchName, args) .catch(err => logger.error(err)); - expect(githubService.deleteBranch).toBeCalledWith('test/webhook'); + expect(githubService.deleteBranch).toBeCalledWith('test/webhook'); expect(gitlabService.deleteBranch).not.toBeCalled(); }); }); @@ -91,7 +91,7 @@ describe('DeleteBranchRunnable', () => { .catch(err => logger.error(err)); expect(githubService.deleteBranch).not.toBeCalled(); - expect(gitlabService.deleteBranch).toBeCalledWith('test/webhook'); + expect(gitlabService.deleteBranch).toBeCalledWith('test/webhook'); }); }); }); diff --git a/src/runnables/webhook.runnable.spec.ts b/src/runnables/webhook.runnable.spec.ts index 54b1d361..920f767a 100644 --- a/src/runnables/webhook.runnable.spec.ts +++ b/src/runnables/webhook.runnable.spec.ts @@ -77,7 +77,7 @@ describe('WebhookRunnable', () => { user: 'my name', content: 'my content', }), - JSON.stringify({}), + {}, ); }); }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 9a363495..a3500436 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -32,11 +32,11 @@ export class Utils { separator: string = ',', ): string[] { if (typeof input === 'string') { - return render(input, data) + return Utils.render(input, data) .split(separator) .filter(f => f !== ''); } - return render(input.toString(), data) + return Utils.render(input.toString(), data) .split(',') // default toString() method separator .filter(f => f !== ''); }