Skip to content

Commit

Permalink
Handle owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Bellangelo committed Aug 24, 2024
1 parent f619d61 commit c3f435f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
comment-body:
description: 'The body of the comment to process.'
required: true
comment-id:
description: 'The id of the comment to update.'
required: true
language:
description: 'The language to use for the custom text.'
default: 'en'
Expand All @@ -15,11 +18,11 @@ inputs:
token:
description: 'GITHUB_TOKEN or a repo scoped PAT.'
default: ${{ github.token }}
required: false
repository:
description: 'The full name of the repository in which to create or update a comment.'
default: ${{ github.repository }}
comment-id:
description: 'The id of the comment to update.'
required: false
outputs:
updated-body:
description: 'The updated comment body with keywords replaced.'
Expand Down
5 changes: 2 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ export default class {
this.#githubHelper = githubHelper
}

updateComment(owner, repo, commentId, oldCommentBody) {
updateComment(repository, commentId, oldCommentBody) {
const newCommentBody = this.#replacer.replace(oldCommentBody)

return this.#githubHelper.updateComment(
owner,
repo,
repository,
commentId,
newCommentBody
)
Expand Down
13 changes: 12 additions & 1 deletion src/GithubHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ import * as core from '@actions/core'
export default class {
#oktokit

/**
* @param {string} githubToken
*/
constructor(githubToken) {
this.#oktokit = github.getOctokit(githubToken)
}

async updateComment(owner, repo, commentId, commentBody) {
/**
*
* @param {string} repository
* @param {string} commentId
* @param {string} commentBody
*/
async updateComment(repository, commentId, commentBody) {
const [owner, repo] = repository.split('/');

await this.#oktokit.rest.issues.updateComment({
owner,
repo,
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ try {
const language = core.getInput('language')
const languageFile = core.getInput('language-file')
const commentId = core.getInput('comment-id')
const owner = core.getInput('owner')
const repo = core.getInput('repo')
const repository = core.getInput('repository')
const token = core.getInput('token')

const replacer = new Replacer(language, languageFile)
const githubHelper = new GithubHelper(token)
const app = new App(replacer, githubHelper)

app.updateComment(owner, repo, commentId, commentBody)
app.updateComment(repository, commentId, commentBody)
} catch (error) {
core.setFailed(`Action failed with error ${error}`)
}

0 comments on commit c3f435f

Please sign in to comment.