-
Notifications
You must be signed in to change notification settings - Fork 53
157 lines (131 loc) · 5.15 KB
/
ontobot.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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 contains 'Hey ontobot'
id: check-body
uses: actions/github-script@v6
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 phrase = 'hey ontobot';
// Check if bodyText includes the phrase
let result = bodyText.includes(phrase);
// If not found in bodyText, 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 {
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
if: needs.check.outputs.phraseExists == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Return issue number
id: gh-script-issue
uses: actions/github-script@v6
with:
script: |
const issue_number = context.issue.number;
return issue_number
- name: Return repository name
id: gh-script-repo
uses: actions/github-script@v6
with:
script: |
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
- name: Install dependencies
run: |
pip install ontobot-change-agent
- name: Run ochange
id: ochange
run: |
cmd="ochange process-issue ${{ env.resource }} \
-r ${{ steps.gh-script-repo.outputs.result }} \
-n ${{ steps.gh-script-issue.outputs.result }} \
-g ${{ secrets.GH_TOKEN }} \
-p MONDO"
if [ "${{ needs.check.outputs.commentId }}" != "" ]; then
cmd="$cmd -c ${{ needs.check.outputs.commentId }}"
fi
echo "Running command: $cmd"
eval $cmd
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.ONTOBOT_APP_ID }}
private-key: ${{ secrets.ONTOBOT_APP_PRIVATE_KEY }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: ${{ env.PR_TITLE }}
with:
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 }}
token: ${{ steps.app-token.outputs.token }}