Skip to content

Commit a0e851c

Browse files
authored
Test Result Report Notification (#459)
Test Result Report Notification for PR post-submit check & Nightly scheduled job
1 parent 8ad95ce commit a0e851c

File tree

6 files changed

+539
-399
lines changed

6 files changed

+539
-399
lines changed

.github/workflows/integration_tests.yml

Lines changed: 114 additions & 384 deletions
Large diffs are not rendered by default.

scripts/gha/build_testapps.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,23 @@
7474
"""
7575

7676
import datetime
77-
from distutils import dir_util
7877
import os
7978
import platform
8079
import shutil
8180
import subprocess
8281
import sys
8382
import json
83+
import attr
8484

8585
from absl import app
8686
from absl import flags
8787
from absl import logging
88+
from distutils import dir_util
8889

89-
import attr
90-
90+
import utils
9191
from integration_testing import config_reader
9292
from integration_testing import test_validation
9393
from integration_testing import xcodebuild
94-
import utils
9594

9695
# Environment variables
9796
_JAVA_HOME = "JAVA_HOME"

scripts/gha/github.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A utility for GitHub REST API.
16+
17+
This script handles GitHub Issue, Pull Request, Comment, Label and Artifact
18+
19+
"""
20+
21+
import requests
22+
import json
23+
import shutil
24+
25+
from absl import logging
26+
27+
OWNER = 'firebase'
28+
REPO = 'firebase-cpp-sdk'
29+
30+
BASE_URL = 'https://api.github.com'
31+
FIREBASE_URL = '%s/repos/%s/%s' % (BASE_URL, OWNER, REPO)
32+
logging.set_verbosity(logging.INFO)
33+
34+
def create_issue(token, title, label):
35+
"""Create an issue: https://docs.github.com/en/rest/reference/issues#create-an-issue"""
36+
url = f'{FIREBASE_URL}/issues'
37+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
38+
data = {'title': title, 'labels': [label]}
39+
with requests.post(url, headers=headers, data=json.dumps(data)) as response:
40+
logging.info("create_issue: %s response: %s", url, response)
41+
return response.json()
42+
43+
44+
def update_issue(token, issue_number, data):
45+
"""Update an issue: https://docs.github.com/en/rest/reference/issues#update-an-issue"""
46+
url = f'{FIREBASE_URL}/issues/{issue_number}'
47+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
48+
with requests.patch(url, headers=headers, data=json.dumps(data)) as response:
49+
logging.info("update_issue: %s response: %s", url, response)
50+
51+
52+
def open_issue(token, issue_number):
53+
update_issue(token, issue_number, data={'state': 'open'})
54+
55+
56+
def close_issue(token, issue_number):
57+
update_issue(token, issue_number, data={'state': 'closed'})
58+
59+
60+
def update_issue_comment(token, issue_number, comment):
61+
update_issue(token, issue_number, data={'body': comment})
62+
63+
64+
def search_issues_by_label(label):
65+
"""https://docs.github.com/en/rest/reference/search#search-issues-and-pull-requests"""
66+
url = f'{BASE_URL}/search/issues?q=repo:{OWNER}/{REPO}+label:"{label}"+is:issue'
67+
headers = {'Accept': 'application/vnd.github.v3+json'}
68+
with requests.get(url, headers=headers) as response:
69+
logging.info("search_issues_by_label: %s response: %s", url, response)
70+
return response.json()["items"]
71+
72+
73+
def list_comments(issue_number):
74+
"""https://docs.github.com/en/rest/reference/issues#list-issue-comments"""
75+
url = f'{FIREBASE_URL}/issues/{issue_number}/comments'
76+
headers = {'Accept': 'application/vnd.github.v3+json'}
77+
with requests.get(url, headers=headers) as response:
78+
logging.info("list_comments: %s response: %s", url, response)
79+
return response.json()
80+
81+
82+
def add_comment(token, issue_number, comment):
83+
"""https://docs.github.com/en/rest/reference/issues#create-an-issue-comment"""
84+
url = f'{FIREBASE_URL}/issues/{issue_number}/comments'
85+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
86+
data = {'body': comment}
87+
with requests.post(url, headers=headers, data=json.dumps(data)) as response:
88+
logging.info("add_comment: %s response: %s", url, response)
89+
90+
91+
def update_comment(token, comment_id, comment):
92+
"""https://docs.github.com/en/rest/reference/issues#update-an-issue-comment"""
93+
url = f'{FIREBASE_URL}/issues/comments/{comment_id}'
94+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
95+
data = {'body': comment}
96+
with requests.patch(url, headers=headers, data=json.dumps(data)) as response:
97+
logging.info("update_comment: %s response: %s", url, response)
98+
99+
100+
def delete_comment(token, comment_id):
101+
"""https://docs.github.com/en/rest/reference/issues#delete-an-issue-comment"""
102+
url = f'{FIREBASE_URL}/issues/comments/{comment_id}'
103+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
104+
with requests.delete(url, headers=headers) as response:
105+
logging.info("delete_comment: %s response: %s", url, response)
106+
107+
108+
def add_label(token, issue_number, label):
109+
"""https://docs.github.com/en/rest/reference/issues#add-labels-to-an-issue"""
110+
url = f'{FIREBASE_URL}/issues/{issue_number}/labels'
111+
headers={}
112+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
113+
data = [label]
114+
with requests.post(url, headers=headers, data=json.dumps(data)) as response:
115+
logging.info("add_label: %s response: %s", url, response)
116+
117+
118+
def delete_label(token, issue_number, label):
119+
"""https://docs.github.com/en/rest/reference/issues#delete-a-label"""
120+
url = f'{FIREBASE_URL}/issues/{issue_number}/labels/{label}'
121+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
122+
with requests.delete(url, headers=headers) as response:
123+
logging.info("delete_label: %s response: %s", url, response)
124+
125+
126+
def list_artifacts(token, run_id):
127+
"""https://docs.github.com/en/rest/reference/actions#list-workflow-run-artifacts"""
128+
url = f'{FIREBASE_URL}/actions/runs/{run_id}/artifacts'
129+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
130+
with requests.get(url, headers=headers) as response:
131+
logging.info("list_artifacts: %s response: %s", url, response)
132+
return response.json()["artifacts"]
133+
134+
135+
def download_artifact(token, artifact_id, output_path):
136+
"""https://docs.github.com/en/rest/reference/actions#download-an-artifact"""
137+
url = f'{FIREBASE_URL}/actions/artifacts/{artifact_id}/zip'
138+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
139+
with requests.get(url, headers=headers, stream=True) as response:
140+
logging.info("download_artifact: %s response: %s", url, response)
141+
with open(output_path, 'wb') as file:
142+
shutil.copyfileobj(response.raw, file)

0 commit comments

Comments
 (0)