Add instances of biogeographic entities #254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create new pull request | |
on: | |
workflow_dispatch: | |
issues: | |
types: [opened, edited] | |
issue_comment: | |
types: [created, edited] | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
outputs: | |
phraseExists: ${{ steps.check-body.outputs.phraseExists }} | |
commentId: ${{ steps.check-body.outputs.commentId }} | |
steps: | |
- name: Check if issue body or any comment contains 'Hey ontobot' | |
id: check-body | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const issue = await github.rest.issues.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}); | |
let bodyText = issue.data.body ? issue.data.body.toLowerCase() : ''; | |
let commentId = null; | |
// Fetch all comments for the issue | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}); | |
// Function to check for the phrase in bodyText and comments | |
function checkForPhrase(bodyText, comments) { | |
const regex = /hey\s*[^a-zA-Z0-9]*\s*ontobot/i; | |
// Check if bodyText includes the phrase | |
let result = regex.test(bodyText); | |
// If not found in bodyText, check in comments | |
if (!result && comments) { | |
for (const comment of comments) { | |
if (regex.test(comment.body)) { | |
result = true; | |
break; | |
} | |
} | |
} | |
return result; | |
} | |
// Check each comment | |
let result = false; | |
for (let comment of comments.data.reverse()) { // Reverse to give precedence to the latest comment | |
if (comment.body.toLowerCase().includes('hey ontobot')) { | |
result = true; | |
commentId = comment.id; | |
break; | |
} | |
} | |
const checkResult = checkForPhrase(bodyText, comments.data); | |
console.log(`Result: ${checkResult}`); | |
console.log(`Comment ID: ${commentId}`); | |
core.setOutput('phraseExists', checkResult); | |
core.setOutput('commentId', commentId); | |
- name: Log phraseExists output | |
run: | | |
echo "phraseExists: ${{ steps.check-body.outputs.phraseExists }}" | |
echo "commentId: ${{ steps.check-body.outputs.commentId }}" | |
echo "Outputs: $(echo '${{ toJSON(steps.check-body.outputs) }}')" | |
- name: Conditional step based on result | |
if: ${{ steps.check-body.outputs.phraseExists == 'true' }} | |
run: echo "The phrase 'Hey ontobot' was found." | |
build: | |
needs: check | |
if: ${{ needs.check.outputs.phraseExists == 'true' }} | |
runs-on: ${{ matrix.os }} | |
container: obolibrary/odkfull:v1.4.3 | |
strategy: | |
matrix: | |
python-version: ["3.9"] | |
os: [ubuntu-latest] | |
steps: | |
- name: Verify the value of phraseExists | |
run: | | |
echo "phraseExists = ${{ needs.check.outputs.phraseExists }}" | |
- name: Checkout main branch | |
uses: actions/checkout@v3 | |
- name: Return issue number | |
id: gh-script-issue | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const issue_number = context.issue.number; | |
return issue_number; | |
- name: Return repository name | |
id: gh-script-repo | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const repo = context.repo.owner + "/" + context.repo.repo; | |
return repo; | |
- name: Set branch name | |
id: vars | |
run: | | |
echo "resource=src/envo/envo-edit.owl" >> $GITHUB_ENV | |
echo "branch-name=kgcl_automation_"${{ steps.gh-script-issue.outputs.result }} >> $GITHUB_ENV | |
echo "comment-id=${{ needs.check.outputs.commentId }}" >> $GITHUB_ENV | |
- name: Get jar & enable plugin. | |
run: | | |
mkdir -p robot-plugins | |
wget https://github.com/gouttegd/kgcl-java/releases/download/kgcl-java-0.4.0/kgcl-robot-plugin-0.4.0.jar -O robot-plugins/kgcl.jar | |
echo "ROBOT_PLUGINS_DIRECTORY=$(pwd)/robot-plugins/" >> "$GITHUB_ENV" | |
- name: Install dependencies | |
run: | | |
pip install ontobot-change-agent | |
- name: Run ochange with comment-id | |
if: ${{ env.comment-id != '' }} | |
id: ochange_with_comment | |
run: | | |
ochange process-issue ${{ env.resource }} \ | |
-r ${{ steps.gh-script-repo.outputs.result }} \ | |
-n ${{ steps.gh-script-issue.outputs.result }} \ | |
-g ${{ secrets.GH_TOKEN }} \ | |
-c ${{ env.comment-id }} | |
- name: Run ochange without comment-id | |
if: ${{ env.comment-id == '' }} | |
id: ochange_without_comment | |
run: | | |
ochange process-issue ${{ env.resource }} \ | |
-r ${{ steps.gh-script-repo.outputs.result }} \ | |
-n ${{ steps.gh-script-issue.outputs.result }} \ | |
-g ${{ secrets.GH_TOKEN }} | |
- name: Clean-up | |
run: rm -rf robot-plugins | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
if: ${{ env.PR_TITLE }} | |
with: | |
# token: ${{ secrets.GH_TOKEN }} | |
branch-suffix: short-commit-hash | |
labels: Automated | |
author: ${{ env.ISSUE_CREATOR }} <${{ env.ISSUE_CREATOR }}@users.noreply.github.com> | |
committer: ${{ env.ISSUE_CREATOR }} <${{ env.ISSUE_CREATOR }}@users.noreply.github.com> | |
body: ${{ env.PR_BODY }} | |
title: ${{ env.PR_TITLE }} | |
base: ${{ github.head_ref }} | |
branch: ${{ env.branch-name }} |