Skip to content

Commit

Permalink
added formatting for branch push event
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Mar 13, 2020
1 parent a405008 commit affef87
Showing 1 changed file with 72 additions and 21 deletions.
93 changes: 72 additions & 21 deletions lib/plugins/output-filter/github-logs-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ const parseRepo = (repository) => {
url: repository.owner.html_url
},
homepage: repository.homepage,
createdAt: repository.created_at,
updatedAt: repository.updated_at,
pushedAt: repository.pushed_at
createdAt: typeof repository.created_at === 'number' ? new Date(repository.created_at * 1000) : repository.created_at,
updatedAt: typeof repository.updated_at === 'number' ? new Date(repository.updated_at * 1000) : repository.updated_at,
pushedAt: typeof repository.pushed_at === 'number' ? new Date(repository.pushed_at * 1000) : repository.pushed_at
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ const parseCommitComment = (event, body) => {

return {
...initEvent({ event, action, webhookName: 'GitHub' }),
message: `${initRepoMessage({ repoName: parsedRepo.name, repoUrl: parsedRepo.url })} - ${event} ${parsedComment.id} - ${parsedComment.url} ${action} by ${initAuthorMessage({ senderUrl: parsedSender.url, senderName: parsedSender.username })}`,
message: `${initRepoMessage({ repoName: parsedRepo.name, repoUrl: parsedRepo.url })} - ${event} ${parsedComment.commitId} - ${parsedComment.url} ${action} by ${initAuthorMessage({ senderUrl: parsedSender.url, senderName: parsedSender.username })}`,
event,
action,
repository: parsedRepo,
Expand Down Expand Up @@ -257,28 +257,79 @@ const parsePush = (event, body) => {
return
}

const {
repoName,
repoUrl
} = parseRepo(repository)
const {
senderUrl,
senderName,
senderAvatarUrl
} = parseSender(sender)
const parsedRepo = parseRepo(repository)
const parsedSender = parseSender(sender)
const parsedBranch = {
name: branchName,
url: buildBranchUrl({ repoUrl: parsedRepo.url, branchName })
}

const branchUrl = buildBranchUrl({ repoUrl, branchName })
const parsedHeadCommit = {
id: headCommit.id,
treeId: headCommit.tree_id,
distinct: headCommit.distinct,
body: headCommit.message,
timestamp: headCommit.timestamp,
url: headCommit.url,
author: {
username: headCommit.author.username
},
committer: {
username: headCommit.committer.username
},
added: headCommit.added,
removed: headCommit.removed,
modified: headCommit.modified
}

const reducedCommits = commits.reduce((acc, curr) => {
const {
id,
tree_id: treeId,
distinct,
message: body,
timestamp,
url,
author: { username: authorUsername },
committer: { username: committerUsername },
added,
removed,
modified
} = curr

const currCommit = {
id,
treeId,
distinct,
body,
timestamp,
url,
author: { username: authorUsername },
committer: { username: committerUsername },
added,
removed,
modified
}

acc[id] = currCommit
return acc
}, {})

const parsedCommits = {
count: commitCount,
...reducedCommits
}

return {
...initEvent({ event, action: 'branch', webhookName: 'GitHub' }),
message: `${initRepoMessage({ repoName, repoUrl })}\n[${commitCount} commit(s)](${(headCommit && headCommit.url) || repoUrl}) pushed to branch [${branchName}](${branchUrl}) by ${initAuthorMessage({ senderUrl, senderName, senderAvatarUrl })}`,
message: `${initRepoMessage({ repoName: parsedRepo.name, repoUrl: parsedRepo.url })} ${commitCount} commit(s) - ${(headCommit && headCommit.url) || parsedRepo.url} pushed to branch: ${parsedBranch.name} - ${parsedBranch.url}) by ${initAuthorMessage({ senderUrl: parsedSender.url, senderName: parsedSender.username })}`,
event,
branchName,
branchUrl,
commitCount,
repository,
sender,
headCommit
action: 'branch',
branch: parsedBranch,
repository: parsedRepo,
sender: parsedSender,
headCommit: parsedHeadCommit,
commits: parsedCommits
}
}

Expand Down

0 comments on commit affef87

Please sign in to comment.