Skip to content

Commit

Permalink
defect: pull request commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
titenkov committed Nov 27, 2023
1 parent 195b8b4 commit 6c28c7d
Showing 1 changed file with 55 additions and 40 deletions.
95 changes: 55 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,52 +109,67 @@ function getLinks() {
return links
}

try {
const status = core.getInput('status')
async() => {

const env = getEnv()
const sender = getSender()
const links = getLinks()
try {
const status = core.getInput('status')

const statusIcon = getStatusIcon(status)
const originalCommitMessage = github.context.payload.head_commit ? github.context.payload.head_commit.message
: (github.context.payload.commits ? github.context.payload.commits[0].message : '')
const env = getEnv()
const sender = getSender()
const links = getLinks()

const commitMessage = originalCommitMessage.length > 50 ? originalCommitMessage.substring(0, 50) + '...' : originalCommitMessage
const statusIcon = getStatusIcon(status)

const details = commitMessage
? `>${commitMessage}\n>${links.commit} | By *${sender.name}* on \`${env.branch}\` | ${links.repository}`
: `>By *${sender.name}* on \`${env.branch}\` | ${links.repository}`
const { owner, repo } = github.context.repo

if (!process.env.SLACK_WEBHOOK_URL) {
core.setFailed('Missing SLACK_WEBHOOK_URL environment variable')
return
}
const commit = await github.repos.getCommit({
owner,
repo,
ref: env.commit,
});

const webhook = new IncomingWebhook(process.env.SLACK_WEBHOOK_URL)
const message = {
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `${statusIcon} *${links.job}*`
}
},
{
type: 'context',
elements: [
{
core.debug(`commit: ${JSON.stringify(commit)}`)

const originalCommitMessage = commit && commit.data.commit ? commit.data.commit.message : ''

core.debug(`commit message: ${JSON.stringify(originalCommitMessage)}`)

const commitMessage = originalCommitMessage.length > 50 ? originalCommitMessage.substring(0, 50) + '...' : originalCommitMessage

const details = commitMessage
? `>${commitMessage}\n>${links.commit} | By *${sender.name}* on \`${env.branch}\` | ${links.repository}`
: `>By *${sender.name}* on \`${env.branch}\` | ${links.repository}`

if (!process.env.SLACK_WEBHOOK_URL) {
core.setFailed('Missing SLACK_WEBHOOK_URL environment variable')
return
}

const webhook = new IncomingWebhook(process.env.SLACK_WEBHOOK_URL)
const message = {
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: details
text: `${statusIcon} *${links.job}*`
}
]
}
]
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: details
}
]
}
]
}
;(async () => {
await webhook.send(message)
})()
} catch (error) {
core.setFailed(error.message)
}
;(async () => {
await webhook.send(message)
})()
} catch (error) {
core.setFailed(error.message)
}
}

0 comments on commit 6c28c7d

Please sign in to comment.