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

ci: Add project fields validator #334

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9a1d081
ci: add project-fields-validator
minikin Oct 18, 2024
1f8dbcb
chore: update python and earthly
minikin Oct 21, 2024
1edb413
Update Earthfile
minikin Oct 22, 2024
1d738f3
feat: update ProjectFieldsValidator
minikin Oct 22, 2024
f0e8d76
chore: refactor python code
minikin Oct 22, 2024
debf21b
Update README.md
minikin Oct 22, 2024
dd17f55
Update main.py
minikin Oct 22, 2024
045e5db
chore: ci lint fixes
minikin Oct 22, 2024
a818e6f
Update Earthfile
minikin Oct 22, 2024
a09ca82
Update Earthfile
minikin Oct 23, 2024
46a289d
Update Earthfile
minikin Oct 24, 2024
7e18b29
Update Earthfile
minikin Oct 24, 2024
061098f
Update Earthfile
minikin Oct 24, 2024
f1aadfb
Update Earthfile
minikin Oct 25, 2024
cae42c4
feat: add GitHub action
minikin Oct 25, 2024
a8c6448
Merge branch 'master' into feat/validate-project-fields-in-prs-and-is…
minikin Oct 25, 2024
304b6f2
Update validate-project-fields.yml
minikin Oct 25, 2024
6586bc7
Update validate-project-fields.yml
minikin Oct 25, 2024
c8bc9ed
wip: clean up
minikin Oct 25, 2024
8042e83
chore: add GITHUB_TOKEN
minikin Oct 25, 2024
a5a5f29
Update Earthfile
minikin Oct 25, 2024
33a8b4e
Update validate-project-fields.yml
minikin Oct 25, 2024
6e11382
Update validate-project-fields.yml
minikin Oct 25, 2024
2cc8180
Update validate-project-fields.yml
minikin Oct 25, 2024
fb45eb6
wip
minikin Oct 25, 2024
55ad662
wip
minikin Oct 25, 2024
e4577bd
wip
minikin Oct 25, 2024
dcf7afa
Update validate-project-fields.yml
minikin Oct 25, 2024
7b13c3f
wip
minikin Oct 25, 2024
279e0ae
wip: testing
jmgilman Oct 25, 2024
bcd275e
wip: testing
jmgilman Oct 25, 2024
e427593
wip: testing
jmgilman Oct 25, 2024
d27bbcb
wip: testing
jmgilman Oct 25, 2024
8202e22
chore: merge branch 'master' into feat/validate-project-fields-in-prs…
jmgilman Oct 25, 2024
039d0b9
wip: cleanup
jmgilman Oct 25, 2024
976f449
Update main.py
minikin Oct 27, 2024
a7cd613
Update main.py
minikin Oct 27, 2024
6736c79
Update main.py
minikin Oct 27, 2024
0efd054
Update validate-project-fields.yml
minikin Oct 27, 2024
4a40ecf
Merge branch 'master' into feat/validate-project-fields-in-prs-and-is…
minikin Oct 28, 2024
2c28d0c
Merge branch 'master' into feat/validate-project-fields-in-prs-and-is…
minikin Oct 29, 2024
919ce82
Merge branch 'master' into feat/validate-project-fields-in-prs-and-is…
minikin Nov 4, 2024
dc59408
Merge branch 'master' into feat/validate-project-fields-in-prs-and-is…
minikin Jan 8, 2025
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
32 changes: 32 additions & 0 deletions utilities/project-fields-validator/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
VERSION 0.8

IMPORT github.com/input-output-hk/catalyst-ci/earthly/python:v3.1.7 AS python-ci

check:
minikin marked this conversation as resolved.
Show resolved Hide resolved
FROM python-ci+python-base

COPY . .

DO python-ci+CHECK

VALIDATE_PROJECTS_FIELDS:
FUNCTION

FROM python-ci+python-base

COPY . .

# Set environment variables
ENV ORG_NAME=input-output-hk
ENV PROJECT_NUMBER=102
ARG PR_NUMBER


RUN python3 main.py

# Check the validation results
RUN if [ -f ".github/project_validation_results.txt" ]; then \
echo "Validation failed. See results:" && \
cat .github/project_validation_results.txt && \
exit 1; \
fi
Empty file.
83 changes: 83 additions & 0 deletions utilities/project-fields-validator/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import requests
import json

def run_query(query, variables):
headers = {"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"}
request = requests.post('https://api.github.com/graphql', json={'query': query, 'variables': variables}, headers=headers)
if request.status_code == 200:
return request.json()
else:
raise Exception(f"Query failed with status code: {request.status_code}. {request.json()}")

def get_pr_related_items(org_name, project_number, pr_number):
query = """
query($org: String!, $number: Int!, $prNumber: Int!) {
organization(login: $org) {
projectV2(number: $number) {
items(first: 100) {
nodes {
id
content {
... on PullRequest {
number
}
}
fieldValues(first: 20) {
nodes {
... on ProjectV2ItemFieldTextValue {
field { name }
text
}
... on ProjectV2ItemFieldDateValue {
field { name }
date
}
... on ProjectV2ItemFieldSingleSelectValue {
field { name }
name
}
}
}
}
}
}
}
}
"""
variables = {
"org": org_name,
"number": project_number,
"prNumber": pr_number
}
result = run_query(query, variables)
items = result['data']['organization']['projectV2']['items']['nodes']
return [item for item in items if item['content'] and item['content'].get('number') == pr_number]

def validate_item(item):
required_fields = ['Status', 'Area', 'Priority', 'Estimate', 'Iteration', 'Start', 'End']
field_values = {fv['field']['name']: fv.get('text') or fv.get('date') or fv.get('name')
for fv in item['fieldValues']['nodes']}
empty_fields = [field for field in required_fields if not field_values.get(field)]
return empty_fields

def main():
org_name = os.environ['ORG_NAME']
project_number = int(os.environ['PROJECT_NUMBER'])
pr_number = int(os.environ['PR_NUMBER'])

items = get_pr_related_items(org_name, project_number, pr_number)

validation_errors = []
for item in items:
empty_fields = validate_item(item)
if empty_fields:
validation_errors.append(f"Item ID: {item['id']}, Empty fields: {', '.join(empty_fields)}")

if validation_errors:
with open('.github/project_validation_results.txt', 'w') as f:
for error in validation_errors:
f.write(f"{error}\n")

if __name__ == "__main__":
main()
Loading
Loading