Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- post '/' do
- json = JSON.parse(request.body.read.to_s)
- notification_type = json['object_kind']
- case notification_type
- when 'push'
- push_repo = Cinch::Formatting.format(:green, json['repository']['name'])
- push_refs = Cinch::Formatting.format(:brown, json['ref'])
- push_refs.slice! "refs/heads/"
- push_author = Cinch::Formatting.format(:red, json['user_name'])
- if json['total_commits_count'] > 5
- before_hash = json['before'][0..7].gsub(/\n/, "")
- after_hash = json['after'][0..7].gsub(/\n/, "")
- repo_page = json['repository']['homepage']
- push_url = shorten("#{repo_page}/compare/#{before_hash}...#{after_hash}")
- say "(#{push_repo} * #{after_hash} * #{push_refs}): #{push_author} pushed #{json['total_commits_count']} commits: #{push_url}"
- break
- end
- json['commits'].each do |commit|
- commit_message = commit['message'][0..80].gsub(/\n/, " ")
- if commit_message.length > 80
- puts commit_message.concat("...")
- end
- commit_url = shorten( commit['url'] )
- commit_author = Cinch::Formatting.format(:red, commit['author']['name'])
- commit_hash = commit['id'][0..7].gsub(/\n/, "")
- if (commit_author != push_author)
- commit_author = push_author + " (#{commit_author})"
- end
- say "(#{push_repo} * #{commit_hash} * #{push_refs}): #{commit_author} committed: #{commit_message} #{commit_url}"
- end
- when 'tag_push'
- say "[#{json['repository']['name']}] #{json['user_name']} | New Tag: #{json['ref']}"
- when 'issue'
- issue_url = shorten(json['object_attributes']['url'])
- say "#{json['user']['name']} #{json['object_attributes']['state']} issue ##{json['object_attributes']['iid']}: #{json['object_attributes']['title']} #{issue_url}" if json['object_attributes']['action'] != 'update'
- when 'note'
- note_url = shorten(json['object_attributes']['url'])
- note_name = Cinch::Formatting.format(:red, json['user']['name'])
- note_com_name = Cinch::Formatting.format(:purple, json['commit']['author']['name'])
- say "#{note_name} commented on #{note_com_name}'s commit #{note_url}"
- when 'build'
- if (json['build_status'] == 'failed')
- repo = Cinch::Formatting.format(:green, json['repository']['name'])
- refs = Cinch::Formatting.format(:brown, json['ref'])
- refs.slice! "refs/heads/"
- homepage = json['repository']['homepage']
- builds = json['build_name']
- build_url = shorten(homepage + '/builds/' + json['build_id'].to_s)
- commit_url = shorten(homepage + '/commit/' + json['commit']['sha'])
- say "(#{repo} * #{refs}): #{builds} for commit #{commit_url} FAILED | Build details: #{build_url}"
- end
- end
- status 200
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement