Skip to content

Commit 737ea64

Browse files
ci: create a new action to update custom properties in a repo (#8)
Signed-off-by: Andrew Brandt <andrew.brandt@hashgraph.com> Co-authored-by: Roger Barker <roger.barker@swirldslabs.com>
1 parent f353139 commit 737ea64

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

.github/SECURITY.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
We take the security of update-custom-properties seriously. If you believe you have found a security vulnerability, please report it to us as described below.
6+
7+
**Please do not report security vulnerabilities through public GitHub issues.**
8+
9+
Instead, please report them via email to:
10+
11+
```
12+
maintainers@pandaswhocode.com
13+
```
14+
15+
You should receive a response within 48 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
16+
17+
Please include the following information in your report:
18+
19+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
20+
- Full paths of source file(s) related to the manifestation of the issue
21+
- The location of the affected source code (tag/branch/commit or direct URL)
22+
- Any special configuration required to reproduce the issue
23+
- Step-by-step instructions to reproduce the issue
24+
- Proof-of-concept or exploit code (if possible)
25+
- Impact of the issue, including how an attacker might exploit it
26+
27+
## Preferred Languages
28+
29+
We prefer all communications to be in English.
30+
31+
## Policy
32+
33+
- We will respond to your report within 48 hours with our evaluation and expected resolution time
34+
- If you have followed the instructions above, we will not take legal action against you in regard to your report
35+
- We will keep you informed of the progress towards resolving the issue
36+
- Once the issue is resolved, we will publicly acknowledge your responsible disclosure, if you wish

action.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: 'Custom Properties Update Action'
2+
description: 'Updates the custom properties for all repos in an org to values in org/governance/repo-properties.yaml'
3+
author: 'Andrew Brandt <andrew.brandt@hashgraph.com>'
4+
organization: 'PandasWhoCode'
5+
branding:
6+
icon: 'check-circle'
7+
color: 'purple'
8+
9+
inputs:
10+
token:
11+
description: 'Personal Access Token'
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Install yq (mikefarah's version)
18+
shell: bash
19+
run: |
20+
sudo wget --quiet https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
21+
sudo chmod +x /usr/bin/yq
22+
yq --version # confirm installed
23+
24+
- name: Convert from JSON to YAML
25+
shell: bash
26+
run: |
27+
REPO_NAME=${{ github.event.repository.name }}
28+
YAML_FILE="repo-properties.yaml"
29+
30+
# Convert the YAML file to JSON for parsing
31+
yq eval -o=json repo-properties.yaml > repo-properties.json
32+
33+
- name: Create list of repo names
34+
shell: bash
35+
run: jq -r '.repositories[].name' repo-properties.json > repo-names.txt
36+
37+
- name: Set custom properties in repos
38+
shell: bash
39+
env:
40+
GH_TOKEN: ${{ inputs.token }}
41+
run: |
42+
# Input files
43+
REPO_NAMES_FILE="repo-names.txt"
44+
JSON_FILE="repo-properties.json"
45+
46+
# Extract the org name once
47+
ORG_NAME=$(jq -r '.org' "$JSON_FILE")
48+
echo "Org Name: ${ORG_NAME}"
49+
50+
# Loop over each repo name
51+
while IFS= read -r REPO_NAME; do
52+
echo "Processing repo: ${REPO_NAME}"
53+
54+
# Check if the repo exists
55+
if ! gh api "/repos/${ORG_NAME}/${REPO_NAME}" --silent > /dev/null 2>&1; then
56+
echo " Repository '${ORG_NAME}/${REPO_NAME}' does not exist. Skipping..."
57+
continue
58+
fi
59+
60+
# Extract matching repository object without the 'name' field
61+
repo_props=$(jq -r --arg name "${REPO_NAME}" '
62+
.repositories[]
63+
| select(.name == $name)
64+
| del(.name)
65+
' "$JSON_FILE")
66+
67+
# Check if a match was found
68+
if [[ "$repo_props" == "null" || -z "$repo_props" ]]; then
69+
echo "No matching data found for ${REPO_NAME}, skipping..."
70+
continue
71+
fi
72+
73+
# Iterate over key-value pairs and set custom properties
74+
echo "$repo_props" | jq -r 'to_entries[] | "\(.key)=\(.value)"' | while IFS="=" read -r key value; do
75+
echo " Setting property '${key}' = '${value}' on ${ORG_NAME}/${REPO_NAME}"
76+
# check to see if date here
77+
if [[ "${key}" == *"-date"* || "${key}" == "date-"* ]]; then
78+
if [[ ! "${value}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ && -n "${value}" ]]; then
79+
echo "Repo name is: ${REPO_NAME}"
80+
echo "Property name is: ${key}"
81+
echo "Date Value is: ${value}"
82+
echo "Invalid date format: Date needs to be formatted [YYYY-MM-DD]"
83+
exit 1
84+
fi
85+
fi
86+
# API Call here
87+
gh api --method PATCH -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${ORG_NAME}/${REPO_NAME}/properties/values -f "properties[][property_name]=${key}" -f "properties[][value]=${value}"
88+
done
89+
done < "${REPO_NAMES_FILE}"
90+
echo "Successfully set custom properties!"

repo-properties.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Place this file in the governance repo at the root level to run on the whole organization
2+
org: PandasWhoCode
3+
teams:
4+
- pandas
5+
- reviewers
6+
- admins
7+
repositories:
8+
- name: my-example-repo
9+
last-date-modified: ""
10+
initial-ci-review-by-team: "pandas"
11+
initial-ci-review-date: "2025-04-07"
12+
initial-security-review-by-team: "admins"
13+
initial-security-review-date: "2025-04-15"
14+
last-security-review-by-team: "reviewers"
15+
last-security-review-date: "2025-05-01"

0 commit comments

Comments
 (0)