Skip to content

Commit

Permalink
Rename comments to review_comments (#31)
Browse files Browse the repository at this point in the history
* rename comments to review_comments

* Update README with new name
  • Loading branch information
briansloane authored and KAllan357 committed Oct 19, 2018
1 parent f792609 commit fb95a3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This tap:
- [Issues](https://developer.github.com/v3/issues/#list-issues-for-a-repository)
- [Pull Requests](https://developer.github.com/v3/pulls/#list-pull-requests)
- [Reviews](https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request)
- [Comments](https://developer.github.com/v3/pulls/comments/)
- [Review Comments](https://developer.github.com/v3/pulls/comments/)
- [Stargazers](https://developer.github.com/v3/activity/starring/#list-stargazers)
- Outputs the schema for each resource
- Incrementally pulls data based on the input state
Expand Down Expand Up @@ -49,12 +49,12 @@ This tap:
"repository": "singer-io/tap-github"}
```
4. Run the tap in discovery mode to get properties.json file
```bash
tap-github --config config.json --discover > properties.json
```
5. In the properties.json file, select the streams to sync
Each stream in the properties.json file has a "schema" entry. To select a stream to sync, add `"selected": true` to that stream's "schema" entry. For example, to sync the pull_requests stream:
```
...
Expand Down Expand Up @@ -83,4 +83,3 @@ This tap:
---
Copyright © 2018 Stitch
24 changes: 12 additions & 12 deletions tap_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'pull_requests':['id'],
'stargazers': ['user_id'],
'reviews': ['id'],
'comments': ['id']
'review_comments': ['id']
}

class AuthException(Exception):
Expand Down Expand Up @@ -76,8 +76,8 @@ def validate_dependencies(selected_stream_ids):
if 'reviews' in selected_stream_ids and 'pull_requests' not in selected_stream_ids:
errs.append(msg_tmpl.format('reviews','pull_requests'))

if 'comments' in selected_stream_ids and 'pull_requests' not in selected_stream_ids:
errs.append(msg_tmpl.format('comments','pull_requests'))
if 'review_comments' in selected_stream_ids and 'pull_requests' not in selected_stream_ids:
errs.append(msg_tmpl.format('review_comments','pull_requests'))

if errs:
raise DependencyException(" ".join(errs))
Expand Down Expand Up @@ -160,11 +160,11 @@ def get_all_pull_requests(schemas, config, state, mdata):
singer.write_bookmark(state, 'reviews', 'since', singer.utils.strftime(extraction_time))
reviews_counter.increment()

# sync comments if that schema is present (only there if selected)
if schemas.get('comments'):
for comment_rec in get_comments_for_pr(pr_num, schemas['comments'], config, state, mdata):
singer.write_record('comments', comment_rec, time_extracted=extraction_time)
singer.write_bookmark(state, 'comments', 'since', singer.utils.strftime(extraction_time))
# sync review comments if that schema is present (only there if selected)
if schemas.get('review_comments'):
for review_comment_rec in get_review_comments_for_pr(pr_num, schemas['review_comments'], config, state, mdata):
singer.write_record('review_comments', review_comment_rec, time_extracted=extraction_time)
singer.write_bookmark(state, 'review_comments', 'since', singer.utils.strftime(extraction_time))

return state

Expand All @@ -184,15 +184,15 @@ def get_reviews_for_pr(pr_number, schema, config, state, mdata):

return state

def get_comments_for_pr(pr_number, schema, config, state, mdata):
def get_review_comments_for_pr(pr_number, schema, config, state, mdata):
repo_path = config['repository']
for response in authed_get_all_pages(
'comments',
'https://api.github.com/repos/{}/pulls/{}/comments'.format(repo_path,pr_number)
):
comments = response.json()
review_comments = response.json()
extraction_time = singer.utils.now()
for comment in comments:
for comment in review_comments:
with singer.Transformer() as transformer:
rec = transformer.transform(comment, schema, metadata=metadata.to_map(mdata))
yield rec
Expand Down Expand Up @@ -362,7 +362,7 @@ def get_stream_from_catalog(stream_id, catalog):

SUB_STREAMS = {
'pull_requests': ['reviews'],
'pull_requests': ['comments']
'pull_requests': ['review_comments']
}

def do_sync(config, state, catalog):
Expand Down
File renamed without changes.

0 comments on commit fb95a3a

Please sign in to comment.