Skip to content

Commit

Permalink
v0.21.2
Browse files Browse the repository at this point in the history
WIP: Develop
  • Loading branch information
bastienterrier authored Jul 11, 2019
2 parents 2ee1c10 + 0732046 commit 5675c89
Show file tree
Hide file tree
Showing 31 changed files with 226 additions and 169 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
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
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
![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

**_Hygie_** is an easy-to-use Open-Source REST API allowing you to interact with GIT events.

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.
Expand Down
6 changes: 3 additions & 3 deletions docs/post-actions/customisablePostActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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).
8 changes: 4 additions & 4 deletions docs/post-actions/existingRunnables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
71 changes: 36 additions & 35 deletions docs/rules/customisableRules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<RuleResult> {
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);
}
}
```
Expand Down
47 changes: 21 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -84,7 +83,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"
},
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/data_access/dataAccess.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
return this.dataProvider.checkIfExist(SourceEnum.EnvsVar, path);
}

/**
* Connection with the dataProvider
*/
Expand Down
12 changes: 7 additions & 5 deletions src/env-var/env-var.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
Loading

0 comments on commit 5675c89

Please sign in to comment.