Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feed/entry/title parsing, and project parsing based on the entry …
…event type
- Loading branch information
1 parent
cb44da9
commit 2468492
Showing
3 changed files
with
108 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module GithubTwitterServer | ||
# these modules extend Feed instances for custom parsing | ||
module Events | ||
module GenericEvent | ||
def project | ||
end | ||
|
||
def content | ||
@content ||= parsed_content | ||
end | ||
end | ||
|
||
module CommitCommentEvent | ||
def project | ||
if title =~ /\w+ commented on (.*)$/ | ||
$1 | ||
else | ||
nil | ||
end | ||
end | ||
|
||
# Comment in a18f575: this mess is gonna get raw, like sushi => | ||
# @c_a18f575 this mess is gonna get raw, like sushi | ||
def content | ||
@content ||= begin | ||
# pull out commit hash and comment | ||
if parsed_content =~ /(\w+)\: (.+)$/ | ||
"@c_#{$1} #{$2}" | ||
else | ||
parsed_content | ||
end | ||
end | ||
end | ||
end | ||
|
||
module PushEvent | ||
def project | ||
if title =~ /\w+ pushed to \w+ at (.*)$/ | ||
$1 | ||
else | ||
nil | ||
end | ||
end | ||
|
||
# put each commit on a line | ||
# @link users | ||
# @link commits | ||
def content | ||
@content ||= begin | ||
parsed_content.dup.tap do |text| | ||
# parse out "HEAD IS (sha)" | ||
text.gsub! /^HEAD is \w+ /, '' | ||
# [['technoweenie', 'sha1'], ['technoweenie', 'sha2']] | ||
commits = text.scan(/(\w+) committed (\w+):/) | ||
msgs = text.split(/\w+ committed \w+: /) | ||
msgs.shift | ||
s = [] | ||
commits.each_with_index do |(user, sha), idx| | ||
s << "#{"@#{user} " if user != author}#{sha} #{msgs[idx]}".strip | ||
end | ||
s = s * "\n" | ||
text.replace \ | ||
case commits.size | ||
when 1 then s | ||
when 0 then '' | ||
else "#{commits.size} commits: #{s}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters