Skip to content

Commit ca2a416

Browse files
authored
fix: test/linters/python_*/** (#5502)
fix: revert python_isort/python_bad_1.py
1 parent a1c890c commit ca2a416

File tree

10 files changed

+40
-1815
lines changed

10 files changed

+40
-1815
lines changed
Lines changed: 4 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,4 @@
1-
import json
2-
from os import getenv, path
3-
from pprint import pprint
4-
import sys
5-
6-
import click # pylint: disable=import-error
7-
from dotenv import load_dotenv # pylint: disable=import-error
8-
import requests # pylint: disable=import-error
9-
10-
env = load_dotenv()
11-
api_url = getenv(API_URL, default='https://api.github.com/graphql' )
12-
github_token = getenv("GITHUB_TOKEN",
13-
default=None)
14-
m = [1, 2, 3]
15-
print(m[len("t"):])
16-
17-
if github_token is None
18-
sys.exit("GitHub Token is not set." +
19-
"Please set the GITHUB_TOKEN env variable in your system or " +
20-
"the .env file of your project.")
21-
22-
client_id = getenv(CLIENT_ID, default='copy_labels.py')
23-
headers = {
24-
'Authorization': 'bearer {github_token}'.format(github_token=github_token),
25-
'Accept': 'application/vnd.github.bane-preview+json'
26-
'Content-Type': 'application/json'
27-
}
28-
29-
def create_label(repo_id, label):
30-
"""
31-
Create label in the supplied repo.
32-
33-
:param repo_id: Unique ID that represents the repo in GitHub
34-
:type repo_id: str
35-
:param label: Object with label information.
36-
:type label: dict
37-
:return: GitHub API request response
38-
"""
39-
40-
query_variables = {
41-
"createLabelInput": {
42-
"color": label["color"],
43-
"description": label["description"],
44-
"name": label["name"],
45-
"repositoryId": repo_id
46-
}
47-
}
48-
49-
with open(path.join(path.dirname(__file__), 'queries/create_label.gql'), 'r') as query_file:
50-
query = "".join(query_file.readlines())
51-
52-
payload = {"query": query, "variables": query_variables}
53-
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
54-
print('Created label {label}'.format(label=label["name"]))
55-
56-
return response
57-
58-
def get_labels(owner, repo):
59-
"""
60-
Gets a list of labels from the supplied repo.
61-
:param owner: Repo owner GitHub login.
62-
:type owner: str
63-
:param repo: Repository name.
64-
:type repo: str
65-
:return: A tuple with the GitHub id for the repository and a list of labels defined in the repository
66-
"""
67-
68-
query_variables = { "owner": owner, "name": repo, }
69-
70-
with open(path.join(path.dirname(__file__), 'queries/get_repo_data.gql'), 'r') as query_file:
71-
query = "".join(query_file.readlines())
72-
73-
payload = {"query": query, "variables": query_variables}
74-
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
75-
76-
status_code = response.status_code
77-
result = response.json()
78-
79-
if status_code >= 200 and status_code <= 300:
80-
repo_id = result["data"]["repository"]["id"]
81-
labels = result["data"]["repository"]["labels"]["nodes"]
82-
83-
return repo_id, labels
84-
else:
85-
raise Exception(
86-
'[ERROR] getting issue labels. Status Code: {status_code} - Message: {result}'.format(
87-
status_code=status_code, result=result["message"]))
88-
89-
def delete_label(label_id):
90-
"""
91-
Delete the specified label
92-
:param label_id: Label's node id.
93-
:type label_id: str
94-
:return: GitHub API request response.
95-
"""
96-
97-
query_variables = {
98-
"deleteLabelInput": {
99-
"clientMutationId": client_id,
100-
"id": label_id,
101-
}
102-
}
103-
104-
with open(path.join(path.dirname(__file__), 'queries/delete_label.gql'), 'r') as query_file:
105-
query = "".join(query_file.readlines())
106-
107-
payload = {"query": query, "variables": query_variables}
108-
result = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
109-
110-
return result
111-
112-
@click.command()
113-
@click.option('--dry', is_flag=True)
114-
@click.argument('source_repo')
115-
@click.argument('target_repo')
116-
def copy_labels(source_repo, target_repo, dry):
117-
"""
118-
Copy labels from the source repository to the target repository.
119-
\f
120-
:param source: The full name of a GitHub repo from where the labels will be copied from. Eg. github/opensourcefriday
121-
:type source: str
122-
:param target: The full name of a GitHub repo to where the labels will be copied. Eg. github/opensourcefriday
123-
:type target: str
124-
:return:
125-
"""
126-
source_owner, source_repo_name = source_repo.split("/")
127-
target_owner, target_repo_name = target_repo.split("/")
128-
129-
try:
130-
print('Fetching labels for {source_repo_name} repo.'.format(source_repo_name=source_repo_name))
131-
_, source_repo_labels = get_labels(source_owner, source_repo_name)
132-
print('Fetched labels for {source_repo_name}'.format(source_repo_name=source_repo_name))
133-
134-
print('Fetching labels for {target_repo_name} repo.'.format(target_repo_name=target_repo_name))
135-
target_repo_id, target_repo_labels = get_labels(target_owner, target_repo_name)
136-
print('Fetched labels for {target_repo_name}'.format(target_repo_name=target_repo_name))
137-
138-
filtered_labels = list(filter(lambda x: x not in target_repo_labels, source_repo_labels))
139-
140-
if dry:
141-
print('This is just a dry run. No labels will be copied/created.')
142-
print('{label_count} labels would have been created.'.format(label_count=len(filtered_labels)))
143-
pprint(filtered_labels, indent=4)
144-
else:
145-
print('Preparing to created {label_count} labels in {target_repo}'.format(
146-
label_count=len(filtered_labels), target_repo=target_repo))
147-
148-
for label in filtered_labels:
149-
create_label(target_repo_id, label)
150-
except Exception as error:
151-
sys.exit(error)
152-
153-
print('Done')
154-
155-
if __name__ == "__main__":
156-
# Pylint doesn't know that @click.command takes care of injecting the
157-
# function parameters. Disabling Pylint error.
158-
copy_labels() # pylint: disable=no-value-for-parameter
1+
a=1;b=2
2+
c=a+b
3+
BROKEN_VAR=BROKEN_VAR
4+
print(c)
Lines changed: 4 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,201 +1,4 @@
1-
import json
2-
import sys
3-
from os import getenv, path
4-
from pprint import pprint
5-
6-
import click # pylint: disable=import-error
7-
import requests # pylint: disable=import-error
8-
from dotenv import load_dotenv # pylint: disable=import-error
9-
10-
env = load_dotenv()
11-
api_url = getenv("API_URL", default="https://api.github.com/graphql")
12-
github_token = getenv("GITHUB_TOKEN", default=None)
13-
m = [1, 2, 3]
14-
print(m[len("t") :])
15-
16-
if github_token is None:
17-
sys.exit(
18-
"GitHub Token is not set."
19-
+ "Please set the GITHUB_TOKEN env variable in your system or "
20-
+ "the .env file of your project."
21-
)
22-
23-
client_id = getenv("CLIENT_ID", default="copy_labels.py")
24-
headers = {
25-
"Authorization": "bearer {github_token}".format(github_token=github_token),
26-
"Accept": "application/vnd.github.bane-preview+json",
27-
"Content-Type": "application/json",
28-
}
29-
30-
31-
def make_request(query, query_variables):
32-
payload = {"query": query, "variables": query_variables}
33-
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
34-
return response
35-
36-
37-
def create_label(repo_id, label):
38-
"""
39-
Create label in the supplied repo.
40-
41-
:param repo_id: Unique ID that represents the repo in GitHub
42-
:type repo_id: str
43-
:param label: Object with label information.
44-
:type label: dict
45-
:return: GitHub API request response
46-
"""
47-
48-
query_variables = {
49-
"createLabelInput": {
50-
"color": label["color"],
51-
"description": label["description"],
52-
"name": label["name"],
53-
"repositoryId": repo_id,
54-
}
55-
}
56-
57-
with open(
58-
path.join(path.dirname(__file__), "queries/create_label.gql"), "r"
59-
) as query_file:
60-
query = "".join(query_file.readlines())
61-
62-
response = make_request(query, query_variables).json()
63-
print("Created label {label}".format(label=label["name"]))
64-
65-
return response
66-
67-
68-
def get_labels(owner, repo):
69-
"""
70-
Gets a list of labels from the supplied repo.
71-
:param owner: Repo owner GitHub login.
72-
:type owner: str
73-
:param repo: Repository name.
74-
:type repo: str
75-
:return: A tuple with the GitHub id for the repository and a list of labels defined in the repository
76-
"""
77-
78-
query_variables = {
79-
"owner": owner,
80-
"name": repo,
81-
}
82-
83-
with open(
84-
path.join(path.dirname(__file__), "queries/get_repo_data.gql"), "r"
85-
) as query_file:
86-
query = "".join(query_file.readlines())
87-
88-
response = make_request(query, query_variables)
89-
90-
status_code = response.status_code
91-
result = response.json()
92-
93-
if status_code >= 200 and status_code <= 300:
94-
repo_id = result["data"]["repository"]["id"]
95-
labels = result["data"]["repository"]["labels"]["nodes"]
96-
97-
return repo_id, labels
98-
else:
99-
raise Exception(
100-
"[ERROR] getting issue labels. Status Code: {status_code} - Message: {result}".format(
101-
status_code=status_code, result=result["message"]
102-
)
103-
)
104-
105-
106-
def delete_label(label_id):
107-
"""
108-
Delete the specified label
109-
:param label_id: Label's node id.
110-
:type label_id: str
111-
:return: GitHub API request response.
112-
"""
113-
114-
query_variables = {
115-
"deleteLabelInput": {"clientMutationId": client_id, "id": label_id}
116-
}
117-
118-
with open(
119-
path.join(path.dirname(__file__), "queries/delete_label.gql"), "r"
120-
) as query_file:
121-
query = "".join(query_file.readlines())
122-
123-
payload = {"query": query, "variables": query_variables}
124-
result = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
125-
126-
return result
127-
128-
129-
@click.command()
130-
@click.option("--dry", is_flag=True)
131-
@click.argument("source_repo")
132-
@click.argument("target_repo")
133-
def copy_labels(source_repo, target_repo, dry):
134-
"""
135-
Copy labels from the source repository to the target repository.
136-
\f
137-
:param source: The full name of a GitHub repo from where the labels will be copied from. Eg. github/opensourcefriday
138-
:type source: str
139-
:param target: The full name of a GitHub repo to where the labels will be copied. Eg. github/opensourcefriday
140-
:type target: str
141-
:return:
142-
"""
143-
source_owner, source_repo_name = source_repo.split("/")
144-
target_owner, target_repo_name = target_repo.split("/")
145-
146-
try:
147-
print(
148-
"Fetching labels for {source_repo_name} repo.".format(
149-
source_repo_name=source_repo_name
150-
)
151-
)
152-
_, source_repo_labels = get_labels(source_owner, source_repo_name)
153-
print(
154-
"Fetched labels for {source_repo_name}".format(
155-
source_repo_name=source_repo_name
156-
)
157-
)
158-
159-
print(
160-
"Fetching labels for {target_repo_name} repo.".format(
161-
target_repo_name=target_repo_name
162-
)
163-
)
164-
target_repo_id, target_repo_labels = get_labels(target_owner, target_repo_name)
165-
print(
166-
"Fetched labels for {target_repo_name}".format(
167-
target_repo_name=target_repo_name
168-
)
169-
)
170-
171-
filtered_labels = list(
172-
filter(lambda x: x not in target_repo_labels, source_repo_labels)
173-
)
174-
175-
if dry:
176-
print("This is just a dry run. No labels will be copied/created.")
177-
print(
178-
"{label_count} labels would have been created.".format(
179-
label_count=len(filtered_labels)
180-
)
181-
)
182-
pprint(filtered_labels, indent=4)
183-
else:
184-
print(
185-
"Preparing to created {label_count} labels in {target_repo}".format(
186-
label_count=len(filtered_labels), target_repo=target_repo
187-
)
188-
)
189-
190-
for label in filtered_labels:
191-
create_label(target_repo_id, label)
192-
except Exception as error:
193-
sys.exit(error)
194-
195-
print("Done")
196-
197-
198-
if __name__ == "__main__":
199-
# Pylint doesn't know that @click.command takes care of injecting the
200-
# function parameters. Disabling Pylint error.
201-
copy_labels() # pylint: disable=no-value-for-parameter
1+
a = 1
2+
b = 2
3+
c = a + b
4+
print(c)

0 commit comments

Comments
 (0)