-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci) notify other repo about push to master (#3046)
This PR introduces boilerplate for sending dispatch_event to other repositories when any code will hit the master Signed-off-by: Bart Smykla <bartek@smykla.com>
- Loading branch information
1 parent
1743828
commit 09a229c
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module.exports = async ({ | ||
github = {}, | ||
owner = 'kumahq', | ||
repo = 'kuma', | ||
}, foundPR = null) => { | ||
if (!foundPR) { | ||
return null | ||
} | ||
|
||
try { | ||
const { number, title } = foundPR; | ||
|
||
const { data = {} } = await github.rest.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number: number, | ||
}); | ||
|
||
const { | ||
user = {}, | ||
merged_by: mergedBy = {}, | ||
labels: fullLabels = [], | ||
} = data; | ||
|
||
const labels = fullLabels.map(({ id, name, description }) => ({ | ||
id, | ||
name, | ||
description, | ||
})); | ||
|
||
return { | ||
number: number, | ||
title: title, | ||
openedBy: { | ||
login: user.login, | ||
id: user.id, | ||
}, | ||
mergedBy: { | ||
login: mergedBy.login, | ||
id: mergedBy.id, | ||
}, | ||
labels, | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
return null; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: "Push" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
notify-about-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 # necessary to have access to scripts directory | ||
|
||
- uses: jwalton/gh-find-current-pr@v1 | ||
id: findPR | ||
with: | ||
state: all | ||
|
||
- name: "Notify other repositories about push to master" | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.NOTIFY_GH_TOKEN }} | ||
script: | | ||
const parsePR = require('./.github/scripts/parsePR.js'); | ||
const { repository = 'kumahq/kuma', payload } = context; | ||
const { before, after, commits = [] } = payload; | ||
const [ owner, repo ] = repository.split('/'); | ||
const pr = await parsePR( | ||
{ github, owner, repo }, | ||
${{ toJSON(steps.findPR.outputs) }}, | ||
); | ||
github.rest.repos.createDispatchEvent({ | ||
owner: '${{ secrets.NOTIFY_OWNER }}', | ||
repo: '${{ secrets.NOTIFY_REPO }}', | ||
event_type: '${{ secrets.NOTIFY_EVENT_TYPE }}', | ||
client_payload: { | ||
before, | ||
after, | ||
pr, | ||
commits: commits.map(({ id }) => id), | ||
}, | ||
}); |