Skip to content

Commit

Permalink
fix: support Created N other repositories record in full activity log
Browse files Browse the repository at this point in the history
  • Loading branch information
user2589 committed Jan 23, 2019
1 parent 8b9f537 commit fc5df30
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
34 changes: 34 additions & 0 deletions fixtures/record/created_other_repositories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="profile-rollup-wrapper py-4 pl-4 position-relative ml-3 js-details-container Details open">
<span class="discussion-item-icon"><svg aria-hidden="true" class="octicon octicon-repo" height="16" version="1.1" viewbox="0 0 12 16" width="12"><path d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z" fill-rule="evenodd"></path></svg></span>
<button aria-expanded="false" class="btn-link f4 muted-link no-underline lh-condensed width-full js-details-target" type="button">
<span class="float-left">
Created
2
other
repositories
</span>
<span class="d-inline-block float-right">
<span aria-label="Collapse" class=" profile-rollup-toggle-closed float-right">
<svg aria-hidden="true" class="octicon octicon-fold" height="16" version="1.1" viewbox="0 0 14 16" width="14"><path d="M7 9l3 3H8v3H6v-3H4l3-3zm3-6H8V0H6v3H4l3 3 3-3zm4 2c0-.55-.45-1-1-1h-2.5l-1 1h3l-2 2h-7l-2-2h3l-1-1H1c-.55 0-1 .45-1 1l2.5 2.5L0 10c0 .55.45 1 1 1h2.5l1-1h-3l2-2h7l2 2h-3l1 1H13c.55 0 1-.45 1-1l-2.5-2.5L14 5z" fill-rule="evenodd"></path></svg>
</span>
<span aria-label="Expand" class="profile-rollup-toggle-open float-right">
<svg aria-hidden="true" class="octicon octicon-unfold" height="16" version="1.1" viewbox="0 0 14 16" width="14"><path d="M11.5 7.5L14 10c0 .55-.45 1-1 1H9v-1h3.5l-2-2h-7l-2 2H5v1H1c-.55 0-1-.45-1-1l2.5-2.5L0 5c0-.55.45-1 1-1h4v1H1.5l2 2h7l2-2H9V4h4c.55 0 1 .45 1 1l-2.5 2.5zM6 6h2V3h2L7 0 4 3h2v3zm2 3H6v3H4l3 3 3-3H8V9z" fill-rule="evenodd"></path></svg>
</span>
</span>
</button>
<ul class="profile-rollup-content mt-1" data-repository-hovercards-enabled="">
<li class="d-block mt-1 py-1" id="contribution-created-repository-1557464-2011-04-01">
<span class="css-truncate css-truncate-target">
<span class="profile-rollup-icon">
<svg aria-hidden="true" class="octicon octicon-repo v-align-middle text-gray-light mr-1" height="16" version="1.1" viewbox="0 0 12 16" width="12"><path d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z" fill-rule="evenodd"></path></svg>
</span>
<a class="mr-2" data-hovercard-type="repository" data-hovercard-url="/Vanuan/npapi-cpp-sdk/hovercard" href="/Vanuan/npapi-cpp-sdk">Vanuan/npapi-cpp-sdk</a>
</span>
<span class="f6 text-gray">
</span>
<time class="float-right f6 text-gray-light pt-1" title="This contribution was made on Apr 1">
Apr 1
</time>
</li>
</ul>
</div>
1 change: 1 addition & 0 deletions fixtures/record/record_test.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"created_issues.html","{""user2589/Q"": {""issues"": 13}}"
"created_repositories.html","{""vmarkovtsev/go-lcss"": {""created_repository"": 1}, ""vmarkovtsev/documentation"": {""created_repository"": 1}, ""vmarkovtsev/NMLM"": {""created_repository"": 1}, ""vmarkovtsev/pyupgrade-opt"": {""created_repository"": 1}, ""vmarkovtsev/etalpmet"": {""created_repository"": 1}, ""vmarkovtsev/rgf"": {""created_repository"": 1}}"
"created_repository.html","{""user2589/Toggl.py"": {""created_repository"": 1}}"
"created_other_repositories.html","{""Vanuan/npapi-cpp-sdk"": {""created_repository"": 1}}"
"joined_github.html","{}"
"created_pull_requests.html","{""mgdg25/Sandbox"": {""pull_requests"": 1}}"
"created_other_pull_requests.html","{""bblfsh/documentation"": {""pull_requests"": 1}, ""nantes-machine-learning-meetup/NMLM"": {""pull_requests"": 1}, ""spacetelescope/asdf"": {""pull_requests"": 4}, ""asottile/pyupgrade"": {""pull_requests"": 3}, ""src-d/style-analyzer"": {""pull_requests"": 10}, ""src-d/wmd-relax"": {""pull_requests"": 2}, ""vmarkovtsev/pyupgrade-opt"": {""pull_requests"": 2}, ""src-d/guide"": {""pull_requests"": 5}, ""src-d/hercules"": {""pull_requests"": 8}, ""RGF-team/rgf"": {""pull_requests"": 1}, ""src-d/lapjv"": {""pull_requests"": 1}, ""bblfsh/client-python"": {""pull_requests"": 1}, ""src-d/conferences"": {""pull_requests"": 1}, ""src-d/blog"": {""pull_requests"": 3}}"
Expand Down
18 changes: 8 additions & 10 deletions stgithub.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _parse_timeline_update_record(record_div):
# reviewed pull requests
title = normalize_text(record_div.button.text)
if re.match(
'Reviewed \\d+ pull requests? in \\d+ repositor(y|ies)', title):
r'Reviewed \d+ pull requests? in \d+ repositor(y|ies)', title):

for repo_div in record_div.find_all(
'div', class_='profile-rollup-summarized'):
Expand All @@ -125,7 +125,7 @@ def _parse_timeline_update_record(record_div):
count = int(count_span.text.split()[0])
record_data[repo]['reviews'] += count

elif re.match('Opened \\d+ (?:other )?issues? in \\d+ repositor(y|ies)',
elif re.match(r'Opened \d+ (?:other )?issues? in \d+ repositor(y|ies)',
title):
for repo_div in record_div.find_all(
'div', class_='profile-rollup-summarized'):
Expand All @@ -137,13 +137,13 @@ def _parse_timeline_update_record(record_div):
count += int(span.text)
record_data[repo]['issues'] += count

elif re.match('Created \\d+ repositor(y|ies)', title):
elif re.match(r'Created \d+ (?:other )?repositor(y|ies)', title):
for link in record_div.find_all(
'a', attrs={'data-hovercard-type': "repository"}):
record_data[link.text]['created_repository'] = 1

elif re.match('Opened \\d+ (?:other )?pull requests? '
'in \\d+ repositor(y|ies)', title):
elif re.match(r'Opened \d+ (?:other )?pull requests? '
r'in \d+ repositor(y|ies)', title):
for repo_div in record_div.find_all(
'div', class_='profile-rollup-summarized'):
repo = repo_div.button.div.span.text
Expand All @@ -154,7 +154,7 @@ def _parse_timeline_update_record(record_div):
count += int(span.text)
record_data[repo]['pull_requests'] += count

elif re.match('Created \\d+ commits? in \\d+ repositor(y|ies)', title):
elif re.match(r'Created \d+ commits? in \d+ repositor(y|ies)', title):
for repo_li in record_div.ul.find_all('li', recursive=False):
li_div = repo_li.div
if not li_div:
Expand Down Expand Up @@ -302,7 +302,6 @@ class Scraper(object):
typically takes couple minutes.
Use this "API" with caution as it might be extremely slow.
This class provides access to several functions available
"""
_instance = None # singleton instance
Expand Down Expand Up @@ -426,9 +425,8 @@ def links_to_recent_user_activity(self, user):
Args:
user (str): The GitHub login of the user.
Returns:
Generator: A generator of two-tuples:
(<%Y-%m-%d date>, link to the activity)
Yields:
Tuple[str, str]: (<%Y-%m-%d date>, link to the activity)
It seems like this feed only includes tags and commits
>>> list(Scraper().links_to_recent_user_activity('user2589')) # doctest: +SKIP
Expand Down

0 comments on commit fc5df30

Please sign in to comment.