Skip to content

Commit

Permalink
Load GitHub's Releases (#53)
Browse files Browse the repository at this point in the history
* Schema for Releases

* Load Releases from API

* Remove the probably non-working bookmark
  • Loading branch information
raphael-riel authored and KAllan357 committed Feb 21, 2019
1 parent c78274e commit acac606
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tap_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'collaborators': ['id'],
'pull_requests':['id'],
'stargazers': ['user_id'],
'releases': ['id'],
'reviews': ['id'],
'review_comments': ['id']
}
Expand Down Expand Up @@ -184,6 +185,30 @@ def do_discover():
# dump catalog
print(json.dumps(catalog, indent=2))

def get_all_releases(schemas, repo_path, state, mdata):
# Releases doesn't seem to have an `updated_at` property, yet can be edited.
# For this reason and since the volume of release can safely be considered low,
# bookmarks were ignored for releases.

with metrics.record_counter('releases') as counter:
for response in authed_get_all_pages(
'releases',
'https://api.github.com/repos/{}/releases?sort=created_at&direction=desc'.format(repo_path)
):
releases = response.json()
extraction_time = singer.utils.now()
for r in releases:
r['_sdc_repository'] = repo_path

# transform and write release record
with singer.Transformer() as transformer:
rec = transformer.transform(r, schemas, metadata=metadata.to_map(mdata))
singer.write_record('releases', rec, time_extracted=extraction_time)
singer.write_bookmark(state, repo_path, 'releases', {'since': singer.utils.strftime(extraction_time)})
counter.increment()

return state

def get_all_pull_requests(schemas, repo_path, state, mdata):
'''
https://developer.github.com/v3/pulls/#list-pull-requests
Expand Down Expand Up @@ -459,6 +484,7 @@ def get_stream_from_catalog(stream_id, catalog):
'assignees': get_all_assignees,
'collaborators': get_all_collaborators,
'pull_requests': get_all_pull_requests,
'releases': get_all_releases,
'stargazers': get_all_stargazers
}

Expand Down
56 changes: 56 additions & 0 deletions tap_github/releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"type": ["null", "object"],
"additionalProperties": false,
"properties": {
"_sdc_repository": {
"type": ["string"]
},
"id": {
"type": ["null", "string"]
},
"url": {
"type": ["null", "string"]
},
"html_url": {
"type": ["null", "string"]
},
"target_commitish": {
"type": ["null", "string"]
},
"tag_name": {
"type": ["null", "string"]
},
"name": {
"type": ["null", "string"]
},
"body": {
"type": ["null", "string"]
},
"draft": {
"type": ["null", "boolean"]
},
"prerelease": {
"type": ["null", "boolean"]
},
"author": {
"type": ["null", "object"],
"additionalProperties": false,
"properties": {
"login": {
"type": ["null", "string"]
},
"id": {
"type": ["null", "integer"]
}
}
},
"created_at": {
"type": ["null", "string"],
"format": "date-time"
},
"published_at": {
"type": ["null", "string"],
"format": "date-time"
}
}
}

0 comments on commit acac606

Please sign in to comment.