Skip to content

Commit

Permalink
feat(action): Add commit update action script
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilsang committed Jun 7, 2024
1 parent 9703804 commit a8479e5
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions .github/actions/netlify-preview/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,45 @@ runs:
HEAD_COMMIT: ${{ inputs.HEAD_COMMIT }}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
async function getExistPrevActionBot(issueNumber) {
const commentListResult = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber
});
const existPrevAction = result.data.find(comment => comment.user.login === 'github-actions[bot]');
return existPrevAction;
}
async function comment(){
const result = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
owner,
repo,
commit_sha: process.env.HEAD_COMMIT,
});
const issueNumber = result.data[0]?.number;
const commentId = false;
console.log(result.data[0]);
if (issueNumber) {
if (commentId) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}`
});
} else {
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}`
});
}
} else {
if (!issueNumber) {
console.log('No PR found for commit ' + process.env.HEAD_COMMIT);
return;
}
const prevActionBot = await getExistPrevActionBot(issueNumber);
if (prevActionBot.id) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: prevActionBot.id,
body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}`
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}`
});
}
}
comment();

0 comments on commit a8479e5

Please sign in to comment.