Skip to content

Commit

Permalink
Merge pull request #265 from RobokopU24/add_GHaction
Browse files Browse the repository at this point in the history
Added a GitHub action...
  • Loading branch information
EvanDietzMorris authored Dec 9, 2024
2 parents 37ce60f + 713f527 commit 502581d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/scripts/Bio_QC_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import requests

PREDICATE_KEYWORDS = ["predicate", "biolink:", "edges"]
LABEL_NAME = "Biological Context QC" # Label to add if keywords are found

# GitHub API variables
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
REPO_NAME = os.getenv("GITHUB_REPOSITORY")
ISSUE_NUMBER = os.getenv("ISSUE_NUMBER")
print("GITHUB_TOKEN:", GITHUB_TOKEN)
print("REPO_NAME:", REPO_NAME)
print("ISSUE_NUMBER:", ISSUE_NUMBER)

headers = {"Authorization": f"Bearer {GITHUB_TOKEN}"}
api_url = f"https://api.github.com/repos/{REPO_NAME}"

def get_issue_details(issue_number):
response = requests.get(f"{api_url}/issues/{issue_number}", headers=headers)
response.raise_for_status()
return response.json()

def add_label(issue_number, label_name):
response = requests.post(
f"{api_url}/issues/{issue_number}/labels",
headers=headers,
json={"labels": [label_name]}
)
response.raise_for_status()
print(f"Label '{label_name}' added to issue/PR #{issue_number}")

def check_keywords_in_text(text, keywords):
return any(keyword in text for keyword in keywords)

def main():
issue_details = get_issue_details(ISSUE_NUMBER)
title = issue_details["title"]
body = issue_details["body"]

if check_keywords_in_text(title, PREDICATE_KEYWORDS) or check_keywords_in_text(body, PREDICATE_KEYWORDS):
add_label(ISSUE_NUMBER, LABEL_NAME)
else:
print("No predicate keywords found.")

if __name__ == "__main__":
main()
32 changes: 32 additions & 0 deletions .github/workflows/label-predicate-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Label Predicate Changes'

on:
pull_request:
types: [opened, edited, synchronize]
issues:
types: [opened, edited]

jobs:
label_check:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install PyGithub
- name: Run predicate check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
run: |
python .github/scripts/Bio_QC_check.py
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ neo4j==5.20.0
pyoxigraph==0.3.22
curies==0.7.9
prefixmaps==0.2.4
bmt==1.4.1
bmt==1.4.1

0 comments on commit 502581d

Please sign in to comment.