diff --git a/.github/workflows/suggest-related-links.yml b/.github/workflows/suggest-related-links.yml index a6a8605..0eef414 100644 --- a/.github/workflows/suggest-related-links.yml +++ b/.github/workflows/suggest-related-links.yml @@ -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- @@ -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' diff --git a/actions/src/main.ts b/actions/src/main.ts index 264b41c..ce6da70 100644 --- a/actions/src/main.ts +++ b/actions/src/main.ts @@ -74,7 +74,7 @@ export async function run(): Promise { 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 { diff --git a/actions/src/suggest.ts b/actions/src/suggest.ts index 0149fc9..1e2074d 100644 --- a/actions/src/suggest.ts +++ b/actions/src/suggest.ts @@ -2,11 +2,12 @@ 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 { +export async function suggest(inps: Inputs, tmpDir: string): Promise { // 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'; @@ -14,5 +15,17 @@ export async function suggest(inps: Inputs): Promise { 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); } diff --git a/models/.gitignore b/models/.gitignore index bdc6960..af09fcd 100644 --- a/models/.gitignore +++ b/models/.gitignore @@ -2,3 +2,4 @@ *.txt suggestions.json training_data/ +fasttext/try-suggest.ts