From 1e27b660fbc56d54dff8dbaa14931a4f10726207 Mon Sep 17 00:00:00 2001 From: raulsh Date: Thu, 10 Mar 2022 21:18:15 -0300 Subject: [PATCH] add tag schema and tag extraction from github --- tap_github/__init__.py | 24 ++++++++++++++++++++++++ tap_github/schemas/tags.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tap_github/schemas/tags.json diff --git a/tap_github/__init__.py b/tap_github/__init__.py index 5c2d768a..a5a17fcf 100644 --- a/tap_github/__init__.py +++ b/tap_github/__init__.py @@ -26,6 +26,7 @@ 'pull_requests':['id'], 'stargazers': ['user_id'], 'releases': ['id'], + 'tags': ['node_id'], 'reviews': ['id'], 'review_comments': ['id'], 'pr_commits': ['id'], @@ -781,6 +782,28 @@ def get_all_releases(schemas, repo_path, state, mdata, _start_date): return state +def get_all_tags(schemas, repo_path, state, mdata, _start_date): + # The volume of tags can safely be considered low + + with metrics.record_counter('tags') as counter: + for response in authed_get_all_pages( + 'tags', + 'https://api.github.com/repos/{}/tags?sort=node_id&direction=desc'.format(repo_path) + ): + tags = response.json() + extraction_time = singer.utils.now() + for t in tags: + t['_sdc_repository'] = repo_path + + # transform and write release record + with singer.Transformer() as transformer: + rec = transformer.transform(t, schemas, metadata=metadata.to_map(mdata)) + singer.write_record('tags', rec, time_extracted=extraction_time) + singer.write_bookmark(state, repo_path, 'tags', {'since': singer.utils.strftime(extraction_time)}) + counter.increment() + + return state + def get_all_pull_requests(schemas, repo_path, state, mdata, start_date): ''' https://developer.github.com/v3/pulls/#list-pull-requests @@ -1099,6 +1122,7 @@ def get_request_timeout(): 'collaborators': get_all_collaborators, 'pull_requests': get_all_pull_requests, 'releases': get_all_releases, + 'tags': get_all_tags, 'stargazers': get_all_stargazers, 'events': get_all_events, 'issue_events': get_all_issue_events, diff --git a/tap_github/schemas/tags.json b/tap_github/schemas/tags.json new file mode 100644 index 00000000..157d3518 --- /dev/null +++ b/tap_github/schemas/tags.json @@ -0,0 +1,33 @@ +{ + "type": ["null", "object"], + "additionalProperties": false, + "properties": { + "name": { + "type": ["null", "string"] + }, + "zipball_url": { + "type": ["null", "string"] + }, + "tarball_url": { + "type": ["null", "string"] + }, + "commit": { + "type": ["null", "object"], + "additionalProperties": false, + "properties": { + "sha": { + "type": ["null", "string"] + }, + "url": { + "type": ["null", "string"] + } + } + }, + "node_id": { + "type": ["null", "string"] + }, + "_sdc_repository": { + "type": ["string"] + } + } +}