Skip to content

Commit b17ea95

Browse files
authored
Merge pull request #217 from creativecommons/new-projects
Update to manage open and untracked issues and pull requests using new projects
2 parents bcc4e1f + b04476d commit b17ea95

14 files changed

+64787
-523
lines changed

.github/workflows/manage_issues.yml.DISABLED renamed to .github/workflows/manage_issues.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ jobs:
2929
- name: Install Python dependencies
3030
run: pipenv sync --system
3131

32-
- name: 'run script to move closed issues to Active Sprint: Done'
33-
run: ./move_closed_issues.py
34-
env:
35-
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
36-
37-
- name: run script to track open untriaged issues and pull requests
38-
run: ./track_issues_and_pull_requests.py
32+
- name: run script to track open and untracked issues and pull requests
33+
run: ./manage_new_issues_and_pull_requests.py
3934
env:
4035
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}

Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ asana = ">=3.2,<4" # "Please use v3.2.X for stable / production environments"
1313
cryptography = ">=42.0.4" # dependency, pinned for security
1414
emoji = "*"
1515
GitPython = ">=3.1.41"
16+
gql = "*"
1617
idna = ">=3.7" # dependency, pinned for security
1718
PyGithub = "*"
19+
Pygments = "*"
1820
PyYAML = "*"
1921
requests = "*"
22+
requests_toolbelt = "*"
2023
urllib3 = ">=2.0.6" # dependency, pinned for security
2124

2225
[requires]

Pipfile.lock

Lines changed: 453 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,42 @@ The following workflows are ordered by schedule frequency and start time.
6262

6363
This creates GitHub teams for the Community teams and updates their membership
6464
based on the [`community_team_members.json`][databag] Lektor databag.
65-
- The databag is used to:
66-
- create the [Community Team Members — Creative Commons Open
67-
Source][ctlistpage] page
68-
- configure GitHub team memberships and repository permissions
69-
- The databag is kept up-to-date by [Push data to CC Open
70-
Source](#push-data-to-cc-open-source), below
65+
- The databag is used to:
66+
- create the [Community Team Members — Creative Commons Open
67+
Source][ctlistpage] page
68+
- configure GitHub team memberships and repository permissions
69+
- The databag is kept up-to-date by [Push data to CC Open
70+
Source](#push-data-to-cc-open-source), below
7171

7272
[sync_teams_yml]: .github/workflows/sync_community_teams.yml
7373
[teams_file]: sync_community_teams.py
7474
[databag]: https://github.com/creativecommons/creativecommons.github.io-source/blob/master/databags/community_team_members.json
7575
[ctlistpage]: https://opensource.creativecommons.org/community/community-team/members/
7676

7777

78-
### Manage issues and pull requests in projects
78+
### Manage new issues and pull requests in projects
7979

8080
| **Workflow** | | |
8181
| -- | --: | --- |
8282
| | Schedule: | Hourly at 45 minutes past the hour (`**:45`) |
8383
| | YAML: | [`manage_issues.yml`][manage_issues] |
8484
| **Script** | | |
85-
| | File: | [`move_closed_issues.py`][move_file] |
86-
| | File: | [`track_issues_and_pull_requests.py`][track_issues] |
85+
| | File: | [`manage_new_issues_and_pull_requests.py`][manage_new_issues] |
8786
| | Common Modules: | [`ccos/`](ccos/) |
8887
| **Env** | | |
8988
| | Required: | `ADMIN_GITHUB_TOKEN` |
9089

91-
This manages issues and pull requests to ensure they are properly tracked
92-
within the [Active Sprint][active_sprint] and [Backlog][backlog] projects:
93-
- Move closed issues from [Backlog][backlog] to [Active
94-
Sprint][active_sprint]: Done
95-
- Track open issues in [Backlog][backlog]: Pending Review
96-
- Track open pull requests in [Active Sprint][active_sprint]: Code Review
90+
This manages new issues and pull requests to ensure they are properly tracked
91+
in a GitHub project:
92+
- [Applications project][proj_applications]
93+
- [Systems project][proj_systems]
94+
- [WebDev project][proj_webdev]
9795

9896
[manage_issues]: .github/workflows/manage_issues.yml
99-
[move_file]: move_closed_issues.py
100-
[track_issues]: track_issues_and_pull_requests.py
101-
[active_sprint]: https://github.com/orgs/creativecommons/projects/7
102-
[backlog]: https://github.com/orgs/creativecommons/projects/10
97+
[manage_new_issues]: manage_new_issues_and_pull_requests.py
98+
[proj_applications]: https://github.com/orgs/creativecommons/projects/15/views/1
99+
[proj_systems]: https://github.com/orgs/creativecommons/projects/22/views/1
100+
[proj_webdev]: https://github.com/orgs/creativecommons/projects/23/views/1
103101

104102

105103
### Normalize Repos
@@ -206,37 +204,59 @@ GitHub Action:
206204
```
207205
208206
209-
## Python Dependencies
207+
## Development
208+
209+
Local development and testing is facilitated by helper scripts:
210+
- `./dev/tools.sh`: Checks and updates Python formatting
211+
- `.dev/test.sh`: Uses act and Docker to test workflows
212+
- [nektos/act](https://github.com/nektos/act): _Run your GitHub Actions
213+
locally 🚀_
214+
210215

211-
- [Asana/python-asana][python-asana]: Official Python client library for the
212-
Asana API v1
213-
- [carpedm20/emoji][emoji]: emoji terminal output for Python
214-
- [gitpython-developers/GitPython][gitpython]: GitPython is a python library
215-
used to interact with Git repositories.
216-
- [PyGithub/PyGithub][pygithub]: Typed interactions with the GitHub API v3
217-
- [PyYAML][pyyaml] is a full-featured YAML framework for the Python programming
218-
language
219-
- [Requests][requests]: HTTP for Humans™
216+
### Python Dependencies
217+
218+
- [Asana/python-asana][python-asana]: _Official Python client library for the
219+
Asana API v1_
220+
- [carpedm20/emoji][emoji]: _e_moji terminal output for Python_
221+
- [gitpython-developers/GitPython][gitpython]: _GitPython is a python library
222+
used to interact with Git repositories._
223+
- [graphql-python/gql][pygql]: _A GraphQL client in Python_
224+
- [PyGithub/PyGithub][pygithub]: _Typed interactions with the GitHub API v3_
225+
- [PyYAML][pyyaml]: _a full-featured YAML framework for the Python
226+
programming language_
227+
- [Requests][requests]: _HTTP for Humans™_
220228

221229
[python-asana]: https://github.com/asana/python-asana
222230
[emoji]: https://github.com/carpedm20/emoji/
223231
[gitpython]: https://github.com/gitpython-developers/GitPython
232+
[pygql]: https://github.com/graphql-python/gql
224233
[pygithub]: https://github.com/pygithub/pygithub
225234
[pyyaml]: https://pyyaml.org/
226235
[requests]: https://requests.readthedocs.io/en/latest/
227236

228237

229-
## Development
238+
### GitHub GraphQL API
230239

231-
Local development and testing is facilitated by helper scripts:
232-
- `./dev/tools.sh`: Checks and updates Python formatting
233-
- `.dev/test.sh`: Uses act and Docker to test workflows
234-
- [nektos/act](https://github.com/nektos/act): _Run your GitHub Actions
235-
locally 🚀_
240+
- [Using the API to manage Projects - GitHub Docs][projectsv2api]
241+
- [Forming calls with GraphQL - GitHub Docs][formingcalls]
242+
243+
[projectsv2api]: https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/using-the-api-to-manage-projects
244+
[formingcalls]: https://docs.github.com/en/graphql/guides/forming-calls-with-graphql
236245

237246

238247
## License
239248

240249
- [`LICENSE`](LICENSE) (Expat/[MIT][mit] License)
241250

242251
[mit]: http://www.opensource.org/licenses/MIT "The MIT License | Open Source Initiative"
252+
253+
254+
### GitHub GraphQL API schema
255+
256+
The GitHub GraphQL API public schema
257+
([`ccos/schema.docs.graphql`][graphqlschema]) was downloaded from [Public
258+
schema - GitHub Docs][publicschema] and is not within scope of the Expat/MIT
259+
license of this project.
260+
261+
[graphqlschema]: ccos/schema.docs.graphql
262+
[publicschema]: https://docs.github.com/en/graphql/overview/public-schema

ccos/gh_utils.py

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,32 @@
33
import os
44
import re
55
import sys
6+
import textwrap
67

78
# Third-party
89
from github import Github
910
from github.GithubException import BadCredentialsException
11+
from gql import Client, gql
12+
from gql.transport.requests import RequestsHTTPTransport
13+
from gql.transport.requests import log as gql_requests_log
14+
from graphql.error.syntax_error import GraphQLSyntaxError
15+
from pygments import highlight
16+
from pygments.formatters import TerminalFormatter
17+
from pygments.lexers import GraphQLLexer
1018
from urllib3.util.retry import Retry
1119

1220
GITHUB_ORGANIZATION = "creativecommons"
21+
GITHUB_RETRY_STATUS_FORCELIST = [
22+
408, # Request Timeout
23+
429, # Too Many Requests
24+
500, # Internal Server Error
25+
502, # Bad Gateway
26+
503, # Service Unavailable
27+
504, # Gateway Timeout
28+
]
1329
GITHUB_USERNAME_DEFAULT = "cc-creativecommons-github-io-bot"
1430
LOG = logging.root
31+
gql_requests_log.setLevel(logging.WARNING)
1532

1633

1734
def get_credentials():
@@ -27,9 +44,43 @@ def get_credentials():
2744
return github_username, github_token
2845

2946

30-
def set_up_github_client():
47+
def gql_query(query):
48+
try:
49+
validated_query = gql(query)
50+
except GraphQLSyntaxError as e:
51+
query_formatted = highlight(
52+
textwrap.indent(textwrap.dedent(query), " "),
53+
GraphQLLexer(),
54+
TerminalFormatter(),
55+
)
56+
error_formatted = textwrap.indent(f"{e}", " ")
57+
LOG.error(
58+
f"Invalid GraphQL syntax:\n{query_formatted}\n{error_formatted}"
59+
)
60+
sys.exit(1)
61+
return validated_query
62+
63+
64+
def setup_github_gql_client():
3165
_, github_token = get_credentials()
32-
LOG.info("Setting up GitHub client...")
66+
LOG.info("Setting up GitHub GraphQL API client")
67+
transport = RequestsHTTPTransport(
68+
url="https://api.github.com/graphql",
69+
headers={"Authorization": f"bearer {github_token}"},
70+
timeout=10,
71+
retries=5,
72+
retry_backoff_factor=10,
73+
retry_status_forcelist=GITHUB_RETRY_STATUS_FORCELIST,
74+
)
75+
with open("ccos/schema.docs.graphql") as file_obj:
76+
gh_schema = file_obj.read()
77+
github_gql_client = Client(transport=transport, schema=gh_schema)
78+
return github_gql_client
79+
80+
81+
def setup_github_rest_client():
82+
_, github_token = get_credentials()
83+
LOG.info("Setting up GitHub Rest API client")
3384
# TODO: Remove retry parameter (urllib3.util.retry.Retry object) once we
3485
# are using PyGithub v2.0
3586
# https://github.com/creativecommons/ccos-scripts/issues/179
@@ -38,7 +89,7 @@ def set_up_github_client():
3889
# for specified HTTP status codes
3990
total=5,
4091
backoff_factor=10,
41-
status_forcelist=list(range(500, 600)),
92+
status_forcelist=GITHUB_RETRY_STATUS_FORCELIST,
4293
allowed_methods={
4394
"DELETE",
4495
"GET",
@@ -49,14 +100,13 @@ def set_up_github_client():
49100
"TRACE",
50101
},
51102
)
52-
github_client = Github(login_or_token=github_token, retry=retry)
53-
LOG.success("done.")
54-
return github_client
103+
github_rest_client = Github(login_or_token=github_token, retry=retry)
104+
return github_rest_client
55105

56106

57107
def get_cc_organization(github_client=None):
58108
if github_client is None:
59-
github_client = set_up_github_client()
109+
github_client = setup_github_rest_client()
60110
LOG.info("Getting CC's GitHub organization...")
61111
try:
62112
gh_org_cc = github_client.get_organization(GITHUB_ORGANIZATION)

ccos/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class IndentFormatter(logging.Formatter):
1212
indentation using tab characters.
1313
"""
1414

15+
# https://en.wikipedia.org/wiki/ANSI_escape_code
1516
color_map = { # ............. Level ## Color ##
1617
logging.CRITICAL: 31, # . CRITICAL 50 red 31
1718
logging.ERROR: 31, # .... ERROR 40 red 31

ccos/manage/projects.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
Applications:
3+
repos:
4+
- .github
5+
- cc-legal-tools-app
6+
- cc-legal-tools-data
7+
- ccos-scripts
8+
- ccrel
9+
- ccrel-guide
10+
- creativecommons.github.io
11+
- creativecommons.github.io-source
12+
- creativecommons.org
13+
- data-science-playground
14+
- eng-misc-scripts
15+
- faq
16+
- legaldb
17+
- licensebuttons
18+
- magical-pony
19+
- mp
20+
- quantifying
21+
- scholars-addenda
22+
- sre-report-to-wikijs
23+
- sre-wp-pull
24+
- stateof
25+
Systems:
26+
repos:
27+
- ansible-dev
28+
- CCID-cas
29+
- CCID-MediaWiki
30+
- index-performance-testing
31+
- rubycas-client-rails
32+
- sre-salt
33+
- sre-salt-prime
34+
- sre-wiki-js
35+
- tech-support
36+
WebDev:
37+
repos:
38+
- attribution-license-plugin
39+
- australian-chapter
40+
- business-toolkit-files
41+
- candela-utility
42+
- cc-accidenz-commons
43+
- cc-assets
44+
- cc-license-chooser
45+
- cc-resource-archive
46+
- cc-usability-prototypes
47+
- certificates-landing-page-theme
48+
- chapters
49+
- chooser
50+
- commoners
51+
- Creative-Commons-Post-Republisher
52+
- creativecommons-base
53+
- creativecommons-certificate
54+
- global-network-strategy
55+
- index-dev-env
56+
- index-prototype
57+
- network-platforms
58+
- og-image-generator
59+
- open4us.org
60+
- queulat
61+
- reversionary-rights
62+
- search
63+
- taaccct
64+
- team-open
65+
- termination-of-transfer
66+
- the-power-of-open
67+
- vocabulary
68+
- vocabulary-theme
69+
- wp-plugin-cc-global-network
70+
- wp-plugin-creativecommons
71+
- wp-plugin-creativecommons-website
72+
- wp-theme-cc-chapter
73+
- wp-theme-cc-commoners
74+
- wp-theme-cctoolkit
75+
- wp-theme-creativecommons.org
76+
- wp-theme-openglam
77+
- wp-theme-summit

0 commit comments

Comments
 (0)