Skip to content

Commit

Permalink
Merge pull request #189 from creativecommons/python-track-issues-and-…
Browse files Browse the repository at this point in the history
…pull-requests

Track issues and pull requests using new Python script
  • Loading branch information
TimidRobot authored Oct 24, 2023
2 parents 5f8326b + 199357d commit 61eff05
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add_community_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
schedule:
- cron: "5 * * * *" # Hourly at 5 minutes past the hour (**:05)
jobs:
build:
add_community_prs:
runs-on: ubuntu-latest
steps:
- name: Handle vocabulary Repo
Expand Down
47 changes: 10 additions & 37 deletions .github/workflows/manage_issues.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
name: Manage Issues in Projects
name: Manage issues and pull requests in projects
on:
workflow_dispatch:
schedule:
- cron: "45 * * * *" # Hourly at 45 minutes past the hour (**:45)
jobs:

add_issues_to_project:
name: Track new issues in Backlog
runs-on: ubuntu-latest
steps:

- name: Track all issues
uses: dhruvkb/[email protected]
with:
ACCESS_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
ORG_NAME: 'creativecommons'
PROJECT_NUMBER: 10 # Backlog
COLUMN_NAME: 'Pending Review'
EXCLUDED_PROJECT_NUMBER: 7 # Active sprint
ISSUE_TYPE: 'issue'
INTERVAL: 1
INTERVAL_UNIT: 'h'

add_prs_to_project:
name: Track PRs in Active Sprint
runs-on: ubuntu-latest
steps:

- name: Track all PRs
uses: dhruvkb/[email protected]
with:
ACCESS_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
ORG_NAME: 'creativecommons'
PROJECT_NUMBER: 7 # Active sprint
COLUMN_NAME: 'Code Review'
ISSUE_TYPE: 'pr'
INTERVAL: 1
INTERVAL_UNIT: 'd'

move_closed_to_done:
name: Move closed issues to Done
manage_issues_and_pull_requests:
name: Manage issues and pull requests
runs-on: ubuntu-latest
steps:

Expand All @@ -62,8 +29,14 @@ jobs:
run: |
pipenv sync --dev --system
- name: run script to move closed issues to Done
- name: 'run script to move closed issues to Active Sprint: Done'
run: |
./move_closed_issues.py
env:
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}

- name: run script to track open issues and pull requests
run: |
./track_issues_and_pull_requests.py
env:
ADMIN_GITHUB_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/normalize_repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- main
jobs:
build:
normalize_repos:
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.11
Expand All @@ -34,7 +34,7 @@ jobs:
with:
name: invalid-issue-report
path: /tmp/invalid_issues.yml
- uses: gautamkrishnar/keepalive-workflow@master
- uses: gautamkrishnar/keepalive-workflow@v1
with:
committer_username: cc-open-source-bot
committer_email: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_data_to_ccos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- main
jobs:
build:
push_data:
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_community_teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- main
jobs:
build:
sync_community_teams:
runs-on: ubuntu-latest
steps:
- name: Setup Python 3.11
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ infrastructure.

- [![Add Community PRs to Project][prs_badge]][prs_link]
- [![Sync Community Teams with GitHub][teams_badge]][teams_link]
- [![Manage Issues in Projects][issues_badge]][issues_link]
- [![Manage issues and pull requests in projects][issues_badge]][issues_link]
- [![Normalize Repos][norm_badge]][norm_link]
- [![Push data to CC Open Source][data_badge]][data_link]

Expand All @@ -17,7 +17,7 @@ infrastructure.
[teams_badge]: https://github.com/creativecommons/ccos-scripts/actions/workflows/sync_community_teams.yml/badge.svg
[teams_link]: #sync-community-teams-with-github
[issues_badge]: https://github.com/creativecommons/ccos-scripts/actions/workflows/manage_issues.yml/badge.svg
[issues_link]: #manage-issues-in-projects
[issues_link]: #manage-issues-and-pull-requests-in-projects
[norm_badge]: https://github.com/creativecommons/ccos-scripts/actions/workflows/normalize_repos.yml/badge.svg
[norm_link]: #normalize-repos
[data_badge]: https://github.com/creativecommons/ccos-scripts/actions/workflows/push_data_to_ccos.yml/badge.svg
Expand Down Expand Up @@ -96,30 +96,31 @@ based on the [`community_team_members.json`][databag] Lektor databag.
[ctlistpage]: https://opensource.creativecommons.org/community/community-team/members/


### Manage Issues in Projects
### Manage issues and pull requests in projects

| **Workflow** | | |
| -- | --: | --- |
| | Schedule: | Hourly at 45 minutes past the hour (`**:45`) |
| | YAML: | [`manage_issues.yml`][manage_issues] |
| **Action** | | |
| | | [dhruvkb/issue-projector][issue_bot] |
| **Script** | | |
| | File: | [`move_closed_issues.py`][move_file] |
| | File: | [`track_issues_and_pull_requests.py`][track_issues] |
| | Common Modules: | [`ccos/`](ccos/) |
| **Env** | | |
| | Required: | `ADMIN_GITHUB_TOKEN` |

This manages issues within the [Active Sprint][active_sprint] and [Backlog][backlog_pending] projects:
- Action: Track new issues in Backlog: Pending Review
- Action: Track PRs in Active Sprint: Code Review
- Script: Move closed issues from Backlog to Active Sprint: Done
This manages issues and pull requests to ensure they are properly tracked
within the [Active Sprint][active_sprint] and [Backlog][backlog] projects:
- Move closed issues from [Backlog][backlog] to [Active
Sprint][active_sprint]: Done
- Track open issues in [Backlog][backlog]: Pending Review
- Track open pull requests in [Active Sprint][active_sprint]: Code Review

[manage_issues]: .github/workflows/manage_issues.yml
[issue_bot]: https://github.com/dhruvkb/issue-projector
[move_file]: move_closed_issues.py
[track_issues]: track_issues_and_pull_requests.py
[active_sprint]: https://github.com/orgs/creativecommons/projects/7
[backlog_pending]: https://github.com/orgs/creativecommons/projects/10
[backlog]: https://github.com/orgs/creativecommons/projects/10


### Normalize Repos
Expand Down
33 changes: 32 additions & 1 deletion ccos/gh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def set_up_github_client():
return github_client


def get_cc_organization(github_client):
def get_cc_organization(github_client=None):
if github_client is None:
github_client = set_up_github_client()
LOG.info("Getting CC's GitHub organization...")
try:
gh_org_cc = github_client.get_organization(GITHUB_ORGANIZATION)
Expand All @@ -68,6 +70,35 @@ def get_cc_organization(github_client):
return gh_org_cc


def get_select_repos(args, gh_org_cc=None):
if gh_org_cc is None:
gh_org_cc = get_cc_organization()
LOG.info("Get select GitHub repositories")
LOG.change_indent(-1)
repos = list(gh_org_cc.get_repos())
LOG.change_indent(+1)
# Skip archived repos
repos_selected = []
for repo in repos:
if not repo.archived:
repos_selected.append(repo)
repos = repos_selected
# Skip non-selected repos
if args.repos:
repos_selected = []
for repo in repos:
if repo.name in args.repos:
repos_selected.append(repo)
repos = repos_selected
if not repos:
raise Exception(
"Specified repositories do not include any valid"
f" repositories: {args.repos}"
)
repos.sort(key=lambda repo: repo.name)
return repos


def get_team_slug_name(project_name, role):
"""
Get the team name and team slug based on GitHub's naming scheme. By
Expand Down
35 changes: 1 addition & 34 deletions normalize_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,6 @@ def setup():
return args


def get_cc_repos(github):
cc = gh_utils.get_cc_organization(github)
return cc.get_repos()


def get_select_repos(args):
LOG.info("Get GitHub data")
github = gh_utils.set_up_github_client()
LOG.change_indent(-1)
repos = list(get_cc_repos(github))
LOG.change_indent(+1)
# Skip archived repos
repos_selected = []
for repo in repos:
if not repo.archived:
repos_selected.append(repo)
repos = repos_selected
# Skip non-selected repos
if args.repos:
repos_selected = []
for repo in repos:
if repo.name in args.repos:
repos_selected.append(repo)
repos = repos_selected
if not repos:
raise ScriptError(
"Specified repositories do not include any valid"
f" repositories: {args.repos}"
)
repos.sort(key=lambda repo: repo.name)
return repos


def set_repo_labels(args, repos):
if args.skip_labels:
return
Expand Down Expand Up @@ -179,7 +146,7 @@ def update_branches(args, repos):
def main():
args = setup()
LOG.info("Starting normalization")
repos = get_select_repos(args)
repos = gh_utils.get_select_repos(args)
set_repo_labels(args, repos)
validate_issue_labels(args, repos)
update_branches(args, repos)
Expand Down
Loading

0 comments on commit 61eff05

Please sign in to comment.