Skip to content

Make Github messages more readable #34

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

Merged
merged 3 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 64 additions & 34 deletions src/event-actions/all.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,79 @@ extractMentionsFromBody = (body) ->
else
""

formatUrl = (adapter, url, text) ->
switch adapter
when "mattermost" || "slack"
"<#{url}|#{text}>"
else
url

module.exports =
commit_comment: (data, callback) ->
commit_comment: (adapter, data, callback) ->
comment = data.comment
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
commit_link = formatUrl adapter, comment.html_url, comment.commit_id

callback "New comment by #{comment.user.login}
on Commit #{comment.commit_id}: #{comment.body} - #{comment.html_url}"
callback "[#{repo_link}] New comment by #{comment.user.login} on commit #{commit_link}: \n\"#{comment.body}\""

create: (data, callback) ->
create: (adapter, data, callback) ->
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
ref_type = data.ref_type
ref = data.ref

callback "New #{ref_type} #{ref} created on #{repo.full_name}"
callback "[#{repo_link}] New #{ref_type} #{ref} created"

delete: (data, callback) ->
delete: (adapter, data, callback) ->
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
ref_type = data.ref_type

ref = data.ref.split('refs/heads/').join('')

callback "#{ref_type} #{ref} deleted on #{repo.full_name}"
callback "[#{repo_link}] #{ref_type} #{ref} deleted"

deployment: (data, callback) ->
deployment: (adapter, data, callback) ->
deploy = data.deployment
repo = data.repository

callback "New deployment #{deploy.id} from: #{repo.full_name} to: #{deploy.environment} started by: #{deploy.creator.login}"

deployment_status: (data, callback) ->
deployment_status: (adapter, data, callback) ->
deploy = data.deployment
deploy_status = data.deployment_status
repo = data.repository

callback "Deployment #{deploy.id} from: #{repo.full_name} to: #{deploy.environment} - #{deploy_status.state} by #{deploy.status.creator.login}"

fork: (data, callback) ->
fork: (adapter, data, callback) ->
forkee = data.forkee
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name

callback "#{repo.full_name} forked by #{forkee.owner.login}"
callback "#{repo_link} forked by #{forkee.owner.login}"

# Needs to handle more then just one page
gollum: (data, callback) ->
gollum: (adapter, data, callback) ->
pages = data.pages
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
sender = data.sender

page = pages[0]

callback "Wiki page: #{page.page_name} #{page.action} on #{repo.full_name} by #{sender.login}"
callback "[#{repo_link}] Wiki page: #{page.page_name} #{page.action} by #{sender.login}"

issues: (data, callback) ->
issues: (adapter, data, callback) ->
issue = data.issue
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
issue_link = formatUrl adapter, issue.html_url, "##{issue.number} \"#{issue.title}\""
action = data.action
sender = data.sender

msg = "Issue \##{issue.number} \"#{issue.title}\""
msg = "[#{repo_link}] Issue #{issue_link}"

switch action
when "assigned"
Expand All @@ -98,36 +112,38 @@ module.exports =
when "unlabeled"
msg += " #{sender.login} removed label: \"#{data.label.name}\" "

callback msg + "- #{issue.html_url}"
callback msg

issue_comment: (data, callback) ->
issue_comment: (adapter, data, callback) ->
issue = data.issue
comment = data.comment
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
comment_link = formatUrl adapter, comment.html_url, "#{issue_pull} ##{issue.number}"

issue_pull = "Issue"

if comment.html_url.indexOf("/pull/") > -1
issue_pull = "Pull Request"

callback "New Comment on #{issue_pull} \##{issue.number} by #{comment.user.login}: \"#{comment.body}\" - #{comment.html_url}"
callback "[#{repo_link}] New comment on #{comment_link} by #{comment.user.login}: \n\"#{comment.body}\""

member: (data, callback) ->
member: (adapter, data, callback) ->
member = data.member
repo = data.repository

callback "Member #{member.login} #{data.action} from #{repo.full_name}"

# Org level event
membership: (data, callback) ->
membership: (adapter, data, callback) ->
scope = data.scope
member = data.member
team = data.team
org = data.organization

callback "#{org.login} #{data.action} #{member.login} to #{scope} #{team.name}"

page_build: (data, callback) ->
page_build: (adapter, data, callback) ->
build = data.build
repo = data.repository
if build?
Expand All @@ -136,24 +152,28 @@ module.exports =
if build.error.message?
callback "Page build for #{data.repository.full_name} errored: #{build.error.message}."

pull_request_review_comment: (data, callback) ->
pull_request_review_comment: (adapter, data, callback) ->
comment = data.comment
pull_req = data.pull_request
base = data.base
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
comment_link = formatUrl adapter, comment.html_url, pull_req.title

callback "New Comment on Pull Request \"#{comment.body}\" by #{comment.user.login}: #{comment.html_url}"
callback "[#{repo_link}] New comment on Pull Request #{comment_link} by #{comment.user.login}: \n\"#{comment.body}\""

pull_request: (data, callback) ->
pull_request: (adapter, data, callback) ->
pull_num = data.number
pull_req = data.pull_request
base = data.base
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
pull_request_link = formatUrl adapter, pull_req.html_url, "##{data.number} \"#{pull_req.title}\""
sender = data.sender

action = data.action

msg = "Pull Request \##{data.number} \"#{pull_req.title}\" "
msg = "[#{repo_link}] Pull Request #{pull_request_link}"

switch action
when "assigned"
Expand All @@ -176,44 +196,54 @@ module.exports =
when "synchronize"
msg +=" synchronized by #{sender.login} "

callback msg + "- #{pull_req.html_url}"
callback msg

push: (data, callback) ->
push: (adapter, data, callback) ->
commit = data.after
commits = data.commits
head_commit = data.head_commit
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
pusher = data.pusher

if !data.deleted
callback "New Commit \"#{head_commit.message}\" to #{repo.full_name} by #{pusher.name}: #{head_commit.url}"
if commits.length == 1
commit_link = formatUrl adapter, head_commit.url, "\"#{head_commit.message}\""
callback "[#{repo_link}] New commit #{commit_link} by #{pusher.name}"
else if commits.length > 1
message = "[#{repo_link}] #{pusher.name} pushed #{commits.length} commits:"
for commit in commits
commit_link = formatUrl adapter, commit.url, "\"#{commit.message}\""
message += "\n#{commit_link}"
callback message

# Org level event
repository: (data, callback) ->
repository: (adapter, data, callback) ->
repo = data.repository
org = data.organization
action = data.action

callback "#{repo.full_name} #{action}"

release: (data, callback) ->
release: (adapter, data, callback) ->
release = data.release
repo = data.repository
repo_link = formatUrl adapter, repo.html_url, repo.name
action = data.action

callback "Release #{release.tag_name} #{action} on #{repo.full_name}"
callback "[#{repo_link}] Release #{release.tag_name} #{action}"

# No clue what to do with this one.
status: (data, callback) ->
status: (adapter, data, callback) ->
commit = data.commit
state = data.state
branches = data.branches
repo = data.repository

callback ""

watch: (data, callback) ->
watch: (adapter, data, callback) ->
repo = data.repository
sender = data.sender

callback "#{repo.full_name} is now being watched by #{sender.login}"
callback "#{repo.full_name} is now being watched by #{sender.login}"
7 changes: 4 additions & 3 deletions src/github-repo-event-notifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = (robot) ->
room = query.room || process.env["HUBOT_GITHUB_EVENT_NOTIFIER_ROOM"]
eventType = req.headers["x-github-event"]
robot.logger.debug "github-repo-event-notifier: Processing event type: \"#{eventType}\"..."
adapter = robot.adapterName

try

Expand All @@ -92,7 +93,7 @@ module.exports = (robot) ->
return false # no match, fail

if filter_parts.length > 0
announceRepoEvent data, eventType, (what) ->
announceRepoEvent adapter, data, eventType, (what) ->
robot.messageRoom room, what
else
console.log "Ignoring #{eventType}:#{data.action} as it's not allowed."
Expand All @@ -102,8 +103,8 @@ module.exports = (robot) ->

res.end ""

announceRepoEvent = (data, eventType, cb) ->
announceRepoEvent = (adapter, data, eventType, cb) ->
if eventActions[eventType]?
eventActions[eventType](data, cb)
eventActions[eventType](adapter, data, cb)
else
cb("Received a new #{eventType} event, just so you know.")