Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: copilot project #144

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Continuous Integration workflow. For more information see:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# https://docs.astral.sh/ruff/integrations/#github-actions

Expand All @@ -17,20 +16,24 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint & format with ruff
run: |
ruff check --output-format github .
ruff format --check .
- name: Test with pytest
run: pytest -v --ignore=purrr .

- name: Verify README.md is up to date
run: |
# If this check fails, run "python update_projects_table.py", and add "README.md" to this PR.
python update_projects_table.py
git diff --name-only --exit-code README.md
# (Enable this step once we have unit tests)
# - name: Test with pytest
# run: pytest -v
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Add "test" once we have unit tests
all: deps format lint # test
all: deps lint format test

deps:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

format: deps
Expand All @@ -11,6 +11,6 @@ lint: deps
ruff check --fix --output-format full .

test: deps
pytest -v
pytest -v --ignore=purrr .

.PHONY: all deps format lint test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ demonstrate basic system features, integration APIs, and best practices.
| [Slack notify on Confluence page created](./confluence_to_slack/) | When Confluence page is created the user will be notified on Slack | confluence, slack |
| [Parse a file in S3 and insert to database](./data_pipeline/) | Triggered by a new GPX file on an S3 bucket, the pipeline code will parse the GPX file and insert it into a database. | aws, http, sqlite3 |
| [Github Actions](./github_actions/) | GitHub workflows that interact across multiple repositories | github |
| [Unregister non active users from Copilot](./github_copilot_seats/) | If Copilot was not used in a preceding period by users, the workflow automatically unregisters and notifies them. Users can ask for their subscription to be reinstated. | githubcopilot, slack |
| [Cancel GitHub Copilot access for inactive users](./github_copilot_seats/) | If Copilot was not used in a preceding period by users, unsubscribe and notify them in Slack. Users can ask for their subscription to be reinstated. | githubcopilot, slack |
| [Google Calendar To Asana](./google_cal_to_asana/) | Creates Asana tasks based on Google Calendar events | calendar, asana |
| [Create Jira ticket from Google form](./google_forms_to_jira/) | Trigger by HTTP request, continue polling Google forms, and create Jira ticket based on the form's data | forms, http, jira |
| [Hacker News Alerts in Slack ](./hackernews/) | Track Hacker News articles by topic and send updates to Slack | slack |
Expand Down
37 changes: 20 additions & 17 deletions github_copilot_seats/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
---
title: Unregister non active users from Copilot
description: If Copilot was not used in a preceding period by users, the workflow automatically unregisters and notifies them. Users can ask for their subscription to be reinstated.
title: Cancel GitHub Copilot access for inactive users
description: If Copilot was not used in a preceding period by users, unsubscribe and notify them in Slack. Users can ask for their subscription to be reinstated.
integrations: ["githubcopilot", "slack"]
categories: ["DevOps"]
---

# GitHub Copilot Registration Pruning
# GitHub Copilot Seat Pruning

This automation searches daily for all users in a GitHub organization that are actively using Copilot.
If Copilot was not used in a preceding period, it automatically unregisters them, and then notifies them.
Users can then optionally ask for their subscription to be reinstated.
This automation runs daily to list all the users in the GitHub organization
who have access to [Copilot](https://github.com/features/copilot). If any of
them haven't used it in a preceding period of time, it marks their seat for
cancellation in the next billing cycle, and notifies them in a Slack DM.

## Before Deploying This AutoKitteh Project:
Users can then optionally respond and ask for the seat to be reassigned back
to them.

- Set the `GITHUB_ORG` in the project's vars.
- Set the `IDLE_USAGE_THRESHOLD` in the project's vars:
- (e.g., `4320` for 72 hours)
- (e.g., `25` for 25 minutes)
- Set the `LOGINS` in the project's vars (optional).
- Set the `LOG_CHANNEL` in the project's vars to the Slack channel name/ID you want to post to.
## Before Deploying This AutoKitteh Project

Set/modify these optional project variables:

- `IDLE_HOURS_THRESHOLD` (default = 72 hours)
- `MANAGED_LOGINS` (default = no one = manage all org users)
- `SLACK_LOG_CHANNEL` (channel name or ID, default = none)

## Slack Usage

- `/autokitteh prune-idle-copilot-seats` invokes the automation immediately.
- `/autokitteh find-idle-copilot-seats` displays the potentially idle seats.
You may use the Slack application's slash command(s) with one of these text
triggers:

> [!WARNING]
> This example currently works only with a [Personal Access Token](https://docs.autokitteh.com/integrations/github/connection/#personal-access-token-pat), specifically a [classic token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic).
- `prune-idle-copilot-seats` - invokes the daily automation immediately
- `find-idle-copilot-seats` - displays the potentially idle seats
15 changes: 7 additions & 8 deletions github_copilot_seats/autokitteh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ version: v1
project:
name: github_copilot_seats
vars:
- name: GITHUB_ORG
value: autokitteh
- name: IDLE_USAGE_THRESHOLD
value: 10 # 72 hours
- # If not empty, only manage GitHub Copilot subscriptions to the specified users, separated by commas.
name: LOGINS
- name: IDLE_HOURS_THRESHOLD
value: 72
# Optional: manage GitHub Copilot subscriptions only for these users, separated by commas.
- name: MANAGED_LOGINS
value: ""
# Optional: Slack channel name or ID, for debugging.
- name: SLACK_LOG_CHANNEL
value: ""
- name: LOG_CHANNEL
value: log
connections:
- name: github_conn
integration: github
Expand Down
53 changes: 0 additions & 53 deletions github_copilot_seats/helpers.py

This file was deleted.

44 changes: 44 additions & 0 deletions github_copilot_seats/message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "You have been removed from the Copilot program due to inactivity",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Please select an option:"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":repeat: Reinstate",
"emoji": true
},
"value": "reinstate",
"action_id": "reinstate-action"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":relieved: OK",
"emoji": true
},
"value": "ok",
"action_id": "ok-action"
}
]
}
]
}
44 changes: 0 additions & 44 deletions github_copilot_seats/msg.json

This file was deleted.

Loading
Loading