-
-
Notifications
You must be signed in to change notification settings - Fork 232
66 lines (61 loc) · 2.7 KB
/
automerge-orphans.yml
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
# This action is centrally managed in https://github.com/asyncapi/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
name: 'Notify on failing automerge'
on:
schedule:
- cron: "0 0 * * *"
jobs:
identify-orphans:
if: startsWith(github.repository, 'asyncapi/')
name: Find orphans and notify
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get list of orphans
uses: actions/github-script@v6
id: orphans
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const query = `query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name){
pullRequests(first: 100, states: OPEN){
nodes{
title
url
author {
resourcePath
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo
};
const { repository: { pullRequests: { nodes } } } = await github.graphql(query, variables);
let orphans = nodes.filter( (pr) => pr.author.resourcePath === '/asyncapi-bot' || pr.author.resourcePath === '/apps/dependabot')
if (orphans.length) {
core.setOutput('found', 'true');
//Yes, this is very naive approach to assume there is just one PR causing issues, there can be a case that more PRs are affected the same day
//The thing is that handling multiple PRs will increase a complexity in this PR that in my opinion we should avoid
//The other PRs will be reported the next day the action runs, or person that checks first url will notice the other ones
core.setOutput('url', orphans[0].url);
core.setOutput('title', orphans[0].title);
}
- if: steps.orphans.outputs.found == 'true'
name: Convert markdown to slack markdown
uses: asyncapi/.github/.github/actions/slackify-markdown@master
id: issuemarkdown
with:
markdown: "-> [${{steps.orphans.outputs.title}}](${{steps.orphans.outputs.url}})"
- if: steps.orphans.outputs.found == 'true'
name: Send info about orphan to slack
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{secrets.SLACK_CI_FAIL_NOTIFY}}
SLACK_TITLE: 🚨 Not merged PR that should be automerged 🚨
SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}}
MSG_MINIMAL: true