Skip to content

Commit

Permalink
Merge branch 'master' into releases/v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanis committed Jun 11, 2020
2 parents cc4e964 + efd6b07 commit 3a6ff06
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add the Nitpicker action to your workflow and allow access to the `secrets.GITHU
```yaml
steps:
...
- uses: mobile-actions/nitpicker@v1
- uses: ethanis/nitpicker@v1
with:
nitpicks: '.github/nitpicks.yml'
token: '${{ secrets.GITHUB_TOKEN }}'
Expand Down
21 changes: 21 additions & 0 deletions __tests__/services/comments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as path from 'path';
import { getCommentBody } from '../../src/services';
import { Constants } from '../../src/constants';

test('read valid config file', () => {
const markdown = 'markdown';
const files = ['package.json', 'src/services/comments.ts'];
const prNumber = 42;
const owner = 'foo';
const repo = 'bar';

const expected = `markdown
--------------
_Caused by:_
- [package.json](https://github.com/foo/bar/pull/42/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2)
- [src/services/comments.ts](https://github.com/foo/bar/pull/42/files#diff-0ea10ba5bc61e4ecb7226e70bec7c02f)`;

const commentBody = getCommentBody(markdown, files, prNumber, owner, repo);

expect(commentBody).toEqual(expected);
});
77 changes: 34 additions & 43 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "typescript-action",
"name": "nitpicker",
"version": "0.0.0",
"private": true,
"description": "TypeScript template action",
"description": "Action to auto-comment",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
Expand All @@ -13,14 +13,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/ethanis/nitpicker.git"
},
"keywords": [
"actions",
"node",
"setup"
],
"author": "YourNameOrOrganization",
"author": "ethanis",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.4",
Expand Down
18 changes: 14 additions & 4 deletions src/services/comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as github from '@actions/github';
import * as core from '@actions/core';
import * as crypto from 'crypto';
import { Comment, PullRequestComment, MatchResult } from '../models';
import { parseContext } from './context';
import { Constants } from '../constants';
Expand Down Expand Up @@ -152,17 +153,26 @@ export async function getExistingComments(
}));
}

function getCommentBody(
export function getCommentBody(
markdown: string,
files: string[],
prNumber: number,
owner: string,
repo: string
): string {
return `${markdown}${Constants.CannedTextSeparator}${files
// const hasher = crypto.createHash('md5');
const links = files.map(file => ({
text: file,
hash: crypto
.createHash('md5')
.update(file)
.digest('hex')
}));

return `${markdown}${Constants.CannedTextSeparator}${links
.map(
m =>
` - [${m}](https://github.com/${owner}/${repo}/pull/${prNumber}/files)`
link =>
` - [${link.text}](https://github.com/${owner}/${repo}/pull/${prNumber}/files#diff-${link.hash})`
)
.join('\n')}`;
}

0 comments on commit 3a6ff06

Please sign in to comment.