Skip to content

Commit 3be60d7

Browse files
fix event data generation for pagination test, update doc strings in sync
1 parent 19689fc commit 3be60d7

File tree

2 files changed

+24
-50
lines changed

2 files changed

+24
-50
lines changed

tap_github/sync.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,41 +126,6 @@ def translate_state(state, catalog, repositories):
126126

127127
for key in previous_state_keys:
128128
# Loop through each key of `bookmarks` available in the previous state.
129-
130-
# Case 1:
131-
# Older connections `bookmarks` contain stream names so check if it is the stream name or not.
132-
# If the previous state's key is found in the stream name list then continue to check other keys. Because we want
133-
# to migrate each stream's bookmark into the repo name as mentioned below:
134-
# Example: {`bookmarks`: {`stream_a`: `bookmark_a`}} to {`bookmarks`: {`repo_a`: {`stream_a`: `bookmark_a`}}}
135-
136-
# Case 2:
137-
# Check if the key is available in the list of currently selected repo's list or not. Newer format `bookmarks` contain repo names.
138-
# Return the state if the previous state's key is not found in the repo name list or stream name list.
139-
140-
# If the state contains a bookmark for `repo_a` and `repo_b` and the user deselects these both repos and adds another repo
141-
# then in that case this function was returning an empty state. Now this change will return the existing state instead of the empty state.
142-
143-
# old state
144-
# {
145-
# "bookmarks": {
146-
# "org/test-repo3": {
147-
# "comments": {"since": "2019-01-01T00:00:00Z"}
148-
# }
149-
# }
150-
# }
151-
# for each repo, check each stream under the repo. If the stream is not in stream names or repositories return state.
152-
# stream should always be in stream_names
153-
154-
# new state
155-
# {
156-
# "bookmarks": {
157-
# "comments" : {
158-
# "org/test-repo3": {"since": "2019-01-01T00:00:00Z"},
159-
# },
160-
# }
161-
# }
162-
# for each stream, loop over repos in stream. If the repo is not a stream name (it wont be) or is not is the list of repos, reutrn state. This could happen, and is the case we are checking for. If the repositories are not selected, new ones will get added the new bookmark way.
163-
164129
for inner_key in state['bookmarks'][key].keys():
165130
if inner_key not in stream_names and inner_key not in repositories:
166131
# Return the existing state if all repos from the previous state are deselected(not found) in the current sync.

tests/test_github_start_date.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import requests
3+
import json
34
from tap_tester import connections, runner, LOGGER
45

56
from base import TestGithubBase
@@ -19,33 +20,41 @@ def name():
1920
def generate_data(self):
2021
# get the token
2122
token = os.getenv("TAP_GITHUB_TOKEN")
22-
url = "https://api.github.com/user/starred/singer-io/test-repo"
23-
headers = {"Authorization": "Bearer {}".format(token)}
24-
25-
# generate a data for 'events' stream: 'watchEvent' ie. star the repo
26-
requests.put(url=url, headers=headers)
27-
# as per the Documentation: https://docs.github.com/en/developers/webhooks-and-events/events/github-event-types#watchevent
28-
# the event is generated when we 'star' a repo, hence 'unstar' it as we can 'star' it next time
29-
requests.delete(url=url, headers=headers)
23+
url = "https://api.github.com/repos/singer-io/test-repo/issues"
24+
headers = {"Authorization": "Bearer {}".format(token),
25+
'Accept': 'application/vnd.github+json'}
26+
data = {
27+
"title": "Test Issue",
28+
"body": "This is a test issue for tap-github pagination test"}
29+
# create and close an issue to generate new event data
30+
response = requests.post(url=url, headers=headers, data=json.dumps(data))
31+
if response.status_code == 201:
32+
issue_number = response.json()['number']
33+
else:
34+
print(f"Failed to create issue: {response.status_code}, {response.text}")
35+
36+
delete_url = f'https://api.github.com/repos/singer-io/test-repo/issues/{issue_number}'
37+
delete_data = {'state': 'closed'}
38+
requests.patch(url=delete_url, headers=headers, data=json.dumps(delete_data))
3039

3140
def test_run(self):
3241
# generate data for 'events' stream
3342
self.generate_data()
3443

35-
date_1 = '2023-04-01T00:00:00Z'
36-
date_2 = '2024-10-08T00:00:00Z'
44+
date_1 = '2020-04-01T00:00:00Z'
45+
date_2 = '2021-10-08T00:00:00Z'
3746
expected_stream_1 = {'commits'}
3847
self.run_test(date_1, date_2, expected_stream_1)
3948

40-
date_2 = '2024-07-13T00:00:00Z'
49+
date_2 = '2022-07-13T00:00:00Z'
4150
expected_stream_2 = {'issue_milestones'}
4251
self.run_test(date_1, date_2, expected_stream_2)
4352

44-
date_2 = '2024-05-06T00:00:00Z'
53+
date_2 = '2022-05-06T00:00:00Z'
4554
expected_stream_3 = {'pr_commits', 'review_comments', 'reviews'}
4655
self.run_test(date_1, date_2, expected_stream_3)
4756

48-
date_2 = '2024-01-27T00:00:00Z'
57+
date_2 = '2022-01-27T00:00:00Z'
4958
expected_stream_4 = self.expected_streams().difference(
5059
expected_stream_1,
5160
expected_stream_2,
@@ -58,10 +67,10 @@ def test_run(self):
5867
# `issues` doesn't have enough data in this range, so we skip it too
5968
self.run_test(date_1, date_2, expected_stream_4)
6069

61-
date_3 = '2024-01-27T00:00:00Z'
70+
date_3 = '2023-01-27T00:00:00Z'
6271
self.run_test(date_1, date_3, {"issues"})
6372

64-
date_4 = '2024-01-01T00:00:00Z'
73+
date_4 = '2023-01-01T00:00:00Z'
6574
self.run_test(date_1, date_4, {'pull_requests'})
6675

6776
# As per the Documentation: https://docs.github.com/en/rest/reference/activity#events

0 commit comments

Comments
 (0)