-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add comment on PR #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* eslint-disable no-console */ | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
|
||
import { CrawlerApiClient } from './crawler-api-client'; | ||
import type { ConfigJson } from './types/configJson'; | ||
|
@@ -9,6 +10,7 @@ import type { GetCrawlersResponseBody } from './types/publicApiJsonResponses'; | |
const CRAWLER_USER_ID = core.getInput('crawler-user-id'); | ||
const CRAWLER_API_KEY = core.getInput('crawler-api-key'); | ||
const CRAWLER_API_BASE_URL = core.getInput('crawler-api-base-url'); | ||
const GITHUB_TOKEN = core.getInput('github-token'); | ||
|
||
// CRAWLER CONFIGURATION | ||
const CRAWLER_NAME = core.getInput('crawler-name').replace(/\//g, '-'); | ||
|
@@ -54,6 +56,34 @@ function getRecordExtractorSource(): string { | |
}`; | ||
} | ||
|
||
function addComment(crawlerId: string): void { | ||
try { | ||
const pathArray = CRAWLER_API_BASE_URL.split('/'); | ||
const protocol = pathArray[0]; | ||
const host = pathArray[2]; | ||
const baseUrl = `${protocol}//${host}`; | ||
|
||
const message = `<p>Check your created <a href="${baseUrl}/admin/crawlers/${crawlerId}/overview" target="_blank">Crawler</a></p> | ||
<p>Check your created index on your <a href="https://www.algolia.com/apps/${ALGOLIA_APP_ID}/explorer/browse/${CRAWLER_NAME}" target="_blank">Algolia Application</a></p>`; | ||
|
||
const context = github.context; | ||
if (context.payload.pull_request === undefined) { | ||
core.info('No pull request found.'); | ||
return; | ||
} | ||
const prNumber = context.payload.pull_request.number; | ||
|
||
const octokit = github.getOctokit(GITHUB_TOKEN); | ||
octokit.rest.issues.createComment({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, would be create to not recreate a comment but find the previous one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just having a look at that GA : https://github.com/marketplace/actions/find-comment |
||
...context.repo, | ||
issue_number: prNumber, | ||
body: message, | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
async function crawlerReindex(): Promise<void> { | ||
let crawlerId = ''; | ||
|
||
|
@@ -80,6 +110,7 @@ async function crawlerReindex(): Promise<void> { | |
|
||
console.log(`---------- Reindexing crawler ${crawlerId} ----------`); | ||
await client.reindex(crawlerId); | ||
addComment(crawlerId); | ||
} | ||
|
||
console.log('---------CRAWLER CONFIG---------'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
"@actions/[email protected]": | ||
version "5.0.0" | ||
resolved "https://registry.npmjs.org/@actions/github/-/github-5.0.0.tgz" | ||
resolved "https://registry.yarnpkg.com/@actions/github/-/github-5.0.0.tgz#1754127976c50bd88b2e905f10d204d76d1472f8" | ||
integrity sha512-QvE9eAAfEsS+yOOk0cylLBIO/d6WyWIOvsxxzdrPFaud39G6BOkUwScXZn1iBzQzHyu9SBkkLSWlohDWdsasAQ== | ||
dependencies: | ||
"@actions/http-client" "^1.0.11" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should have a comment no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the GA tests are running the version 0.6 which doesn't have the comment feature yet. I'm not sure how to test it efficently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's try with the next PR