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

React to product-owners.yml changes #6859

Merged
merged 9 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
# Product Areas - notion.so/sentry/473791bae5bf43399d46093050b77bf0
- name: 'Product Area: Unknown'
color: '8D5494'
- name: 'Product Area: Sign in'
- name: 'Product Area: Sign In'
color: '8D5494'
- name: 'Product Area: Issues'
color: '8D5494'
Expand Down Expand Up @@ -208,12 +208,10 @@
color: '8D5494'
- name: 'Product Area: Help'
color: '8D5494'
- name: 'Product Area: What’s new'
- name: "Product Area: What's New"
hubertdeng123 marked this conversation as resolved.
Show resolved Hide resolved
color: '8D5494'
- name: 'Product Area: Footer'
color: '8D5494'
- name: 'Product Area: Other'
color: '8D5494'
- name: 'Product Area: SDKs - Web Frontend'
color: '8D5494'
- name: 'Product Area: SDKs - Web Backend'
Expand All @@ -224,6 +222,8 @@
color: '8D5494'
- name: 'Product Area: Docs'
color: '8D5494'
- name: 'Product Area: Other'
color: '8D5494'

# Teams
- name: 'Team: Crons'
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/react-to-product-owners-yml-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: React to product-owners.yml changes
on:
# This could be run manually, but the general expectation is that this fires
# from GHA in getsentry/security-as-code on changes there.

workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
name: React to product-owners.yml changes
steps:
- uses: actions/checkout@v2

- uses: getsentry/[email protected]
with:
python-version: 3.11.3

- name: Get an auth token
id: token
uses: getsentry/[email protected]
with:
app_id: ${{ secrets.SENTRY_INTERNAL_APP_ID }}
private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}

- name: React to product-owners.yml changes
shell: bash
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
run: ./bin/react-to-product-owners-yml-changes.sh
47 changes: 47 additions & 0 deletions bin/react-to-product-owners-yml-changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import os, sys, yaml
from os.path import realpath, join, dirname

# Run from project root.
os.chdir(realpath(join(dirname(sys.argv[0]), '..')))

PREFIX = 'Product Area: '
LABELS_YAML = '.github/labels.yml'

product_owners = yaml.safe_load(open(sys.argv[1]))
labels = open(LABELS_YAML)

fastforward = False
head = []
product_areas = ["- name: 'Product Area: Unknown'\n", " color: '8D5494'\n"]
tail = []
current = head

# Best to look the other way, Buck. This is just waaaay easier than trying to
# use ruamel.yaml to preserve comments and other formatting.

for line in labels:
chadwhitacre marked this conversation as resolved.
Show resolved Hide resolved
if line == '\n':
fastforward = False
elif fastforward:
continue
elif line.startswith("- name: 'Product Area: "):
fastforward = True
current = tail
continue
current.append(line)

for area in product_owners['by_area']:
if "'" in area:
product_areas.append(f'- name: "Product Area: {area}"\n')
chadwhitacre marked this conversation as resolved.
Show resolved Hide resolved
else:
product_areas.append(f"- name: 'Product Area: {area}'\n")
product_areas.append(f" color: '8D5494'\n")

product_areas += ["- name: 'Product Area: Other'\n", " color: '8D5494'\n"]

with open('.github/labels.yml', 'w+') as fp:
fp.writelines(head)
fp.writelines(product_areas)
fp.writelines(tail)
15 changes: 15 additions & 0 deletions bin/react-to-product-owners-yml-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
cd ..
gh repo clone https://github.com/getsentry/security-as-code /tmp/security-as-code
sha=$(git -C /tmp/security-as-code rev-parse @)
pip3 install pyyaml==6.0
./bin/react-to-product-owners-yml-changes.py /tmp/security-as-code/rbac/lib/product-owners.yml
branch="getsantry/update-product-area-labels-${sha:0:8}"
git checkout -b "$branch"
git add .
git commit -m "Sync with product-owners.yml in security-as-code@${sha:0:8}"
git push --set-upstream origin "$branch"
gh pr create --fill
gh pr merge --squash --auto
chadwhitacre marked this conversation as resolved.
Show resolved Hide resolved