Skip to content

Commit 05ad05a

Browse files
artem1205jbfbell
authored andcommitted
✨Source GitHub: add new stream Contributor Activity (#30615)
Co-authored-by: artem1205 <[email protected]>
1 parent 0cf0815 commit 05ad05a

File tree

9 files changed

+168
-10
lines changed

9 files changed

+168
-10
lines changed

airbyte-integrations/connectors/source-github/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=1.0.4
15+
LABEL io.airbyte.version=1.1.0
1616
LABEL io.airbyte.name=airbyte/source-github

airbyte-integrations/connectors/source-github/acceptance-test-config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ acceptance_tests:
3434
- name: "events"
3535
bypass_reason: "Only events created within the past 90 days can be showed"
3636
ignored_fields:
37+
contributor_activity:
38+
- name: weeks
39+
bypass_reason: "depend on changing data"
40+
- name: total
41+
bypass_reason: "depend on changing data"
3742
workflows:
3843
- name: created_at
3944
bypass_reason: value may be returned in different time zones
@@ -84,6 +89,7 @@ acceptance_tests:
8489
configured_catalog_path: "integration_tests/configured_catalog.json"
8590
future_state:
8691
future_state_path: "integration_tests/abnormal_state.json"
92+
skip_comprehensive_incremental_tests: true
8793
full_refresh:
8894
tests:
8995
- config_path: "secrets/config.json"

airbyte-integrations/connectors/source-github/integration_tests/configured_catalog.json

+10
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
"destination_sync_mode": "append",
8080
"cursor_field": ["created_at"]
8181
},
82+
{
83+
"stream": {
84+
"name": "contributor_activity",
85+
"json_schema": {},
86+
"supported_sync_modes": ["full_refresh"],
87+
"source_defined_primary_key": [["id"]]
88+
},
89+
"sync_mode": "full_refresh",
90+
"destination_sync_mode": "overwrite"
91+
},
8292
{
8393
"stream": {
8494
"name": "deployments",

airbyte-integrations/connectors/source-github/integration_tests/expected_records.jsonl

+4-2
Large diffs are not rendered by default.

airbyte-integrations/connectors/source-github/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data:
55
connectorSubtype: api
66
connectorType: source
77
definitionId: ef69ef6e-aa7f-4af1-a01d-ef775033524e
8-
dockerImageTag: 1.0.4
8+
dockerImageTag: 1.1.0
99
maxSecondsBetweenMessages: 5400
1010
dockerRepository: airbyte/source-github
1111
githubIssueLabel: source-github
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"$schema": "https://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"title": "Contributor Activity",
5+
"properties": {
6+
"name": {
7+
"type": ["null", "string"]
8+
},
9+
"email": {
10+
"type": ["string", "null"]
11+
},
12+
"login": {
13+
"type": ["null", "string"]
14+
},
15+
"id": {
16+
"type": ["null", "integer"]
17+
},
18+
"node_id": {
19+
"type": ["null", "string"]
20+
},
21+
"avatar_url": {
22+
"type": ["null", "string"],
23+
"format": "uri"
24+
},
25+
"gravatar_id": {
26+
"type": ["string", "null"]
27+
},
28+
"url": {
29+
"type": ["null", "string"],
30+
"format": "uri"
31+
},
32+
"html_url": {
33+
"type": ["null", "string"],
34+
"format": "uri"
35+
},
36+
"followers_url": {
37+
"type": ["null", "string"],
38+
"format": "uri"
39+
},
40+
"following_url": {
41+
"type": ["null", "string"]
42+
},
43+
"gists_url": {
44+
"type": ["null", "string"]
45+
},
46+
"starred_url": {
47+
"type": ["null", "string"]
48+
},
49+
"subscriptions_url": {
50+
"type": ["null", "string"],
51+
"format": "uri"
52+
},
53+
"organizations_url": {
54+
"type": ["null", "string"],
55+
"format": "uri"
56+
},
57+
"repos_url": {
58+
"type": ["null", "string"],
59+
"format": "uri"
60+
},
61+
"events_url": {
62+
"type": ["null", "string"]
63+
},
64+
"repository": {
65+
"type": ["null", "string"]
66+
},
67+
"received_events_url": {
68+
"type": ["null", "string"],
69+
"format": "uri"
70+
},
71+
"type": {
72+
"type": ["null", "string"]
73+
},
74+
"site_admin": {
75+
"type": ["null", "boolean"]
76+
},
77+
"starred_at": {
78+
"type": ["null", "string"]
79+
},
80+
"total": {
81+
"type": ["null", "integer"]
82+
},
83+
"weeks": {
84+
"type": "array",
85+
"items": {
86+
"type": "object",
87+
"properties": {
88+
"w": {
89+
"type": ["null", "integer"],
90+
"description": "Start of the week, given as a Unix timestamp."
91+
},
92+
"a": {
93+
"type": ["null", "integer"],
94+
"description": "Number of additions"
95+
},
96+
"d": {
97+
"type": ["null", "integer"],
98+
"description": "Number of deletions"
99+
},
100+
"c": {
101+
"type": ["null", "integer"],
102+
"description": "Number of commits"
103+
}
104+
}
105+
}
106+
}
107+
}
108+
}

airbyte-integrations/connectors/source-github/source_github/source.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CommitCommentReactions,
2222
CommitComments,
2323
Commits,
24+
ContributorActivity,
2425
Deployments,
2526
Events,
2627
IssueCommentReactions,
@@ -259,6 +260,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
259260
CommitCommentReactions(**repository_args_with_start_date),
260261
CommitComments(**repository_args_with_start_date),
261262
Commits(**repository_args_with_start_date, branches_to_pull=branches_to_pull, default_branches=default_branches),
263+
ContributorActivity(**repository_args),
262264
Deployments(**repository_args_with_start_date),
263265
Events(**repository_args_with_start_date),
264266
IssueCommentReactions(**repository_args_with_start_date),

airbyte-integrations/connectors/source-github/source_github/streams.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def request_params(
205205

206206
def request_headers(self, **kwargs) -> Mapping[str, Any]:
207207
# Without sending `User-Agent` header we will be getting `403 Client Error: Forbidden for url` error.
208-
return {
209-
"User-Agent": "PostmanRuntime/7.28.0",
210-
}
208+
return {"User-Agent": "PostmanRuntime/7.28.0"}
211209

212210
def parse_response(
213211
self,
@@ -1543,3 +1541,33 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
15431541
record["team_slug"] = stream_slice["team_slug"]
15441542
record["username"] = stream_slice["username"]
15451543
return record
1544+
1545+
1546+
class ContributorActivity(GithubStream):
1547+
"""
1548+
API docs: https://docs.github.com/en/rest/metrics/statistics?apiVersion=2022-11-28#get-all-contributor-commit-activity
1549+
"""
1550+
1551+
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
1552+
return f"repos/{stream_slice['repository']}/stats/contributors"
1553+
1554+
def request_headers(self, **kwargs) -> Mapping[str, Any]:
1555+
params = super().request_headers(**kwargs)
1556+
params.update({"Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28"})
1557+
return params
1558+
1559+
def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str, Any]) -> MutableMapping[str, Any]:
1560+
record["repository"] = stream_slice["repository"]
1561+
record.update(record.pop("author"))
1562+
return record
1563+
1564+
def should_retry(self, response: requests.Response) -> bool:
1565+
"""
1566+
If the data hasn't been cached when you query a repository's statistics, you'll receive a 202 response, need to retry to get results
1567+
see for more info https://docs.github.com/en/rest/metrics/statistics?apiVersion=2022-11-28#a-word-about-caching
1568+
"""
1569+
if super().should_retry(response) or response.status_code == requests.codes.ACCEPTED:
1570+
return True
1571+
1572+
def backoff_time(self, response: requests.Response) -> Optional[float]:
1573+
return 10 if response.status_code == requests.codes.ACCEPTED else super().backoff_time(response)

docs/integrations/sources/github.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ This connector outputs the following full refresh streams:
7474

7575
- [Assignees](https://docs.github.com/en/rest/reference/issues#list-assignees)
7676
- [Branches](https://docs.github.com/en/rest/reference/repos#list-branches)
77+
- [Contributor Activity](https://docs.github.com/en/rest/metrics/statistics?apiVersion=2022-11-28#get-all-contributor-commit-activity)
7778
- [Collaborators](https://docs.github.com/en/rest/reference/repos#list-repository-collaborators)
7879
- [Issue labels](https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository)
7980
- [Organizations](https://docs.github.com/en/rest/reference/orgs#get-an-organization)
@@ -163,9 +164,10 @@ The GitHub connector should not run into GitHub API limitations under normal usa
163164

164165
| Version | Date | Pull Request | Subject |
165166
|:--------|:-----------|:------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
166-
| 1.0.4 | 2023-08-03 | [29031](https://github.com/airbytehq/airbyte/pull/29031) | Reverted `advancedAuth` spec changes |
167-
| 1.0.3 | 2023-08-01 | [28910](https://github.com/airbytehq/airbyte/pull/28910) | Updated `advancedAuth` broken references |
168-
| 1.0.2 | 2023-07-11 | [28144](https://github.com/airbytehq/airbyte/pull/28144) | Add `archived_at` property to `Organizations` schema parameter |
167+
| 1.1.0 | 2023-08-03 | [30615](https://github.com/airbytehq/airbyte/pull/30615) | Add new stream `Contributor Activity` |
168+
| 1.0.4 | 2023-08-03 | [29031](https://github.com/airbytehq/airbyte/pull/29031) | Reverted `advancedAuth` spec changes |
169+
| 1.0.3 | 2023-08-01 | [28910](https://github.com/airbytehq/airbyte/pull/28910) | Updated `advancedAuth` broken references |
170+
| 1.0.2 | 2023-07-11 | [28144](https://github.com/airbytehq/airbyte/pull/28144) | Add `archived_at` property to `Organizations` schema parameter |
169171
| 1.0.1 | 2023-05-22 | [25838](https://github.com/airbytehq/airbyte/pull/25838) | Deprecate "page size" input parameter |
170172
| 1.0.0 | 2023-05-19 | [25778](https://github.com/airbytehq/airbyte/pull/25778) | Improve repo(s) name validation on UI |
171173
| 0.5.0 | 2023-05-16 | [25793](https://github.com/airbytehq/airbyte/pull/25793) | Implement client-side throttling of requests |

0 commit comments

Comments
 (0)