Issues templates don't offer a general template #846
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: dapr-bot | |
on: | |
issue_comment: {types: created} | |
jobs: | |
daprbot: | |
name: bot-processor | |
runs-on: ubuntu-latest | |
steps: | |
- name: Comment analyzer | |
uses: actions/github-script@v1 | |
with: | |
github-token: ${{secrets.DAPR_BOT_TOKEN}} | |
script: | | |
// list of owner who can control dapr-bot workflow | |
// TODO: Read owners from OWNERS file. | |
const owners = [ | |
"artursouza", | |
"mukundansundar", | |
"wcs1only", | |
"berndverst", | |
"tmacam", | |
]; | |
const payload = context.payload; | |
const issue = context.issue; | |
const isFromPulls = !!payload.issue.pull_request; | |
const commentBody = payload.comment.body; | |
if (!isFromPulls && commentBody && commentBody.indexOf("/assign") == 0) { | |
if (!issue.assignees || issue.assignees.length === 0) { | |
await github.issues.addAssignees({ | |
owner: issue.owner, | |
repo: issue.repo, | |
issue_number: issue.number, | |
assignees: [context.actor], | |
}) | |
} | |
return; | |
} | |
// actions above this check are enabled for everyone. | |
if (owners.indexOf(context.actor) < 0) { | |
return; | |
} | |
if (commentBody && commentBody.indexOf("/make-me-laugh") == 0) { | |
const result = await github.request("https://official-joke-api.appspot.com/random_joke"); | |
jokedata = result.data; | |
joke = "I have a bad feeling about this."; | |
if (jokedata && jokedata.setup && jokedata.punchline) { | |
joke = `${jokedata.setup} - ${jokedata.punchline}`; | |
} | |
await github.issues.createComment({ | |
owner: issue.owner, | |
repo: issue.repo, | |
issue_number: issue.number, | |
body: joke, | |
}); | |
return; | |
} | |
if (isFromPulls && commentBody) { | |
if (commentBody.indexOf("/ok-to-test") == 0) { | |
// Get pull request | |
const pull = await github.pulls.get({ | |
owner: issue.owner, | |
repo: issue.repo, | |
pull_number: issue.number | |
}); | |
if (pull && pull.data) { | |
// Get commit id and repo from pull head | |
const testPayload = { | |
pull_head_ref: pull.data.head.sha, | |
pull_head_repo: pull.data.head.repo.full_name, | |
command: "ok-to-test", | |
issue: issue, | |
}; | |
// Fire repository_dispatch event to trigger certification test | |
await github.repos.createDispatchEvent({ | |
owner: issue.owner, | |
repo: issue.repo, | |
event_type: "validate-examples", | |
client_payload: testPayload, | |
}); | |
} | |
} | |
} |