Skip to content

Commit

Permalink
feat: suggest links
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Sep 17, 2020
1 parent a0c218f commit 01f93fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/suggest-related-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/actions-suggest-related-links-tmp
path: |
~/.cache/pip
~/actions-suggest-related-links-tmp
key: ${{ runner.os }}-action-${{ hashFiles('~/actions-suggest-related-links-tmp/training-data.json') }}
restore-keys: |
${{ runner.os }}-action-
Expand All @@ -56,8 +58,9 @@ jobs:
cp ~/actions-suggest-related-links-tmp/training-data.json .
echo '${{ github.event.issue.title }} ${{ github.event.issue.body }}' > input.txt
python3 train.py -d training-data.json -test input.txt
cp ./suggestions.json ~/actions-suggest-related-links-tmp/
- uses: peaceiris/actions-suggest-related-links@v0.8.8
- uses: peaceiris/actions-suggest-related-links@v0.9.0
if: github.event_name != 'pull_request'
with:
repository: 'peaceiris/actions-gh-pages'
2 changes: 1 addition & 1 deletion actions/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function run(): Promise<void> {
const eventType = context.payload.action;
if (eventType === 'opened') {
core.info(`[INFO] event type: ${eventType}`);
await suggest(inps);
await suggest(inps, tmpDir);
} else if (eventType === 'edited') {
core.warning(`[WARN] ${eventType} event type is not supported`);
} else {
Expand Down
19 changes: 16 additions & 3 deletions actions/src/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@ import {GitHubAPI} from './github-api';
import {Inputs} from './interfaces';
import {context} from '@actions/github/lib/utils';
import {md2text, removeSymbols} from './preprocess';
import fs from 'fs';
import path from 'path';

export async function suggest(inps: Inputs): Promise<void> {
export async function suggest(inps: Inputs, tmpDir: string): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const body = `${(context.payload.issue as any).body}`;
const githubAPI = new GitHubAPI(inps.GithubToken, context.repo.owner, context.repo.repo);
const suggestBody = (() => {
if (body === '') {
return 'context body is empty';
} else {
return removeSymbols(md2text(body));
}
})();
await githubAPI.createComment(suggestBody);
console.log(suggestBody);

const results = JSON.parse(fs.readFileSync(path.join(tmpDir, 'suggestions.json'), 'utf8'));
const topNcount = 3;
let commentBody = '';
for (let i = 0; i < topNcount; i++) {
commentBody += `- [${results[i].title}](${results[i].html_url}) (${results[
i
].probability.toFixed(3)})\n`;
}

const githubAPI = new GitHubAPI(inps.GithubToken, context.repo.owner, context.repo.repo);
await githubAPI.createComment(commentBody);
}
1 change: 1 addition & 0 deletions models/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.txt
suggestions.json
training_data/
fasttext/try-suggest.ts

0 comments on commit 01f93fd

Please sign in to comment.