Skip to content

Commit

Permalink
Updated ontobot.yml (#1535)
Browse files Browse the repository at this point in the history
* Update ontobot.yml

* Update ontobot.yml

* Update ontobot.yml

* Update ontobot.yml: remove commented wget

* testing escape chars

* moved escape char outwards

* olled back

* update to latest

* Update kgcl-java version

* Update Workflow
  • Loading branch information
hrshdhgd authored Aug 29, 2024
1 parent 528c616 commit 1dd03ec
Showing 1 changed file with 82 additions and 20 deletions.
102 changes: 82 additions & 20 deletions .github/workflows/ontobot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ name: Create new pull request
on:
workflow_dispatch:
issues:
types: [ opened, edited ]
types: [opened, edited]
issue_comment:
types: [created, edited]

jobs:
check:
runs-on: ubuntu-latest
outputs:
phraseExists: ${{ steps.check-body.outputs.result }}
commentId: ${{ steps.check-body.outputs.commentId }}
steps:
- name: Check if issue body contains 'Hey ontobot'
- name: Check if issue body or any comment contains 'Hey ontobot'
id: check-body
uses: actions/github-script@v6
with:
Expand All @@ -21,11 +24,71 @@ jobs:
repo: context.repo.repo,
issue_number: context.issue.number
});
if (!issue.data.body) {
console.log('Issue body is empty or null');
return false;
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
for (let comment of comments.reverse()) { // Reverse to give precedence to the latest comment
if (comment.body.toLowerCase().includes(phrase)) {
result = true;
commentId = comment.id;
break;
}
}
return issue.data.body.toLowerCase().includes('hey ontobot');
return {
result: result,
commentId: result ? commentId : null
};
}
const checkResult = checkForPhrase(bodyText, comments.data);
console.log(`Result: ${checkResult.result}`);
console.log(`Comment ID: ${checkResult.commentId}`);
console.log(`Check Result: ${JSON.stringify(checkResult)}`);
core.setOutput('phraseExists', checkResult.result);
core.setOutput('commentId', checkResult.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
Expand All @@ -35,7 +98,7 @@ jobs:
strategy:
matrix:
python-version: ["3.9"]
os: [ ubuntu-latest ]
os: [ubuntu-latest]

steps:
- name: Checkout main branch
Expand All @@ -45,33 +108,31 @@ jobs:
id: gh-script-issue
uses: actions/github-script@v6
with:
# github-token: ${{ secrets.GH_TOKEN }}
script: |
const issue_number = context.issue.number
const repo = context.repo.owner+"/"+context.repo.repo
return issue_number
const issue_number = context.issue.number;
return issue_number;
- name: Return repository name
id: gh-script-repo
uses: actions/github-script@v6
with:
# github-token: ${{ secrets.GH_TOKEN }}
script: |
const repo = context.repo.owner+"/"+context.repo.repo
return repo
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-0.2.0/kgcl-robot-plugin-0.2.0.jar -O robot-plugins/kgcl.jar
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
Expand All @@ -82,14 +143,15 @@ jobs:
ochange process-issue ${{ env.resource }} \
-r ${{ steps.gh-script-repo.outputs.result }} \
-n ${{ steps.gh-script-issue.outputs.result }} \
-g ${{ secrets.GH_TOKEN }}
-g ${{ secrets.GH_TOKEN }} \
-c ${{ env.comment-id }}
- name: Clean-up
run: rm -rf robot-plugins

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
if: ${{ env.PR_TITLE}}
if: ${{ env.PR_TITLE }}
with:
# token: ${{ secrets.GH_TOKEN }}
branch-suffix: short-commit-hash
Expand Down

0 comments on commit 1dd03ec

Please sign in to comment.