Skip to content

Commit

Permalink
Merge pull request #93 from INCATools/comment-trigger
Browse files Browse the repository at this point in the history
ontobot now reads comments of an issue too!
  • Loading branch information
hrshdhgd authored Jun 26, 2024
2 parents d5458d6 + 37f0902 commit 6a786f5
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 119 deletions.
59 changes: 39 additions & 20 deletions .github/workflows/new-pr-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
# 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,27 @@
# 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;

# const comments = await github.rest.issues.listComments({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: context.issue.number
# });

# for (const comment of comments.data) {
# if (comment.body.toLowerCase().includes('hey ontobot')) {
# bodyText += ' ' + comment.body.toLowerCase();
# commentId = comment.id;
# }
# }
# return issue.data.body.includes('Hey ontobot');

# return {
# result: bodyText.includes('hey ontobot'),
# commentId: commentId
# };

# build:
# needs: check
Expand All @@ -35,7 +54,7 @@
# strategy:
# matrix:
# python-version: ["3.9"]
# os: [ ubuntu-latest ]
# os: [ubuntu-latest]

# steps:
# - name: Checkout main branch
Expand All @@ -45,33 +64,31 @@
# 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 "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.3.2/kgcl-robot-plugin-0.3.2.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,20 +99,22 @@
# 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 }}
# # ! OR using standalone JAR file.
# # ! ochange process-issue ${{ env.resource }} \
# # ! -r ${{ steps.gh-script-repo.outputs.result }} \
# # ! -n ${{ steps.gh-script-issue.outputs.result }} \
# # ! -g ${{ secrets.GH_TOKEN }} \
# # ! -p ${{ env.comment-id }} \
# # ! -j kgcl-robot.jar

# - 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
58 changes: 38 additions & 20 deletions .github/workflows/new-pr.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# name: Create new pull request
# # 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,29 @@
# 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
# });

# // Check each comment for the phrase
# for (const comment of comments.data) {
# if (comment.body.toLowerCase().includes('hey ontobot')) {
# bodyText += ' ' + comment.body.toLowerCase();
# commentId = comment.id;
# }
# }
# return issue.data.body.toLowerCase().includes('hey ontobot');

# return {
# result: bodyText.includes('hey ontobot'),
# commentId: commentId
# };

# build:
# needs: check
Expand All @@ -34,7 +55,7 @@
# strategy:
# matrix:
# python-version: ["3.9"]
# os: [ ubuntu-latest ]
# os: [ubuntu-latest]

# steps:
# - uses: actions/checkout@v3
Expand All @@ -47,26 +68,23 @@
# 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/ontology/mondo-edit.obo" >> $GITHUB_ENV
# echo "branch-name=ochange_automation_"${{ steps.gh-script-issue.outputs.result }} >> $GITHUB_ENV
# echo "branch-name=ochange_automation_${{ steps.gh-script-issue.outputs.result }}" >> $GITHUB_ENV

# - name: Install dependencies
# run: |
Expand All @@ -79,16 +97,16 @@
# -r ${{ steps.gh-script-repo.outputs.result }} \
# -n ${{ steps.gh-script-issue.outputs.result }} \
# -g ${{ secrets.GH_TOKEN }} \
# -p XXXX
# -p PREFIX_OF_RESOURCE \
# -c ${{ needs.check.outputs.commentId }}

# - name: Create Pull Request
# uses: peter-evans/create-pull-request@v4
# if: ${{ env.PR_TITLE}}
# if: ${{ env.PR_TITLE }}
# with:
# branch-suffix: short-commit-hash
# labels: Automated
# body: ${{ env.PR_BODY }}
# title: ${{ env.PR_TITLE }}
# base: ${{ github.head_ref }}
# branch: ${{ env.branch-name }}
# # token: ${{ secrets.GH_TOKEN }}
28 changes: 21 additions & 7 deletions src/ontobot_change_agent/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ def get_issues(
:param state: State of the issue e.g. open, close etc., defaults to "open"
:yield: Issue names that match the regex/label/number.
"""
if token is None:
token_file = TOKEN_FILE
with open(token_file, "r") as t:
token = t.read().rstrip()

g = Github(token)
repo = g.get_repo(repository_name)
repo = _get_repo_object(repository_name, token)
global ISSUE_TEMPLATE_DIR
ISSUE_TEMPLATE_DIR = repo.contents_url.replace("{+path}", ISSUE_TEMPLATE_DIR)
label_object = None
Expand All @@ -104,6 +98,26 @@ def get_issues(
yield None


def get_comment_from_repo(repository_name: str, token: str = None, comment_id: int = 0):
"""Get a comment from a Github repository."""
repo = _get_repo_object(repository_name, token)

for comment in repo.get_issues_comments():
if comment.id == comment_id:
return comment.body
return None


def _get_repo_object(repository_name: str, token: str = None):
if token is None:
token_file = TOKEN_FILE
with open(token_file, "r") as t:
token = t.read().rstrip()

g = Github(token)
return g.get_repo(repository_name)


def _extract_info_from_issue_object(issue: Issue) -> dict:
issue_as_dict = issue.__dict__
important_info = {k: issue_as_dict[RAW_DATA][k] for k in ISSUE_KEYS}
Expand Down
Loading

0 comments on commit 6a786f5

Please sign in to comment.