Skip to content

Instantly share code, notes, and snippets.

@woodie
Created April 29, 2021 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodie/441b4457b0776406e890edff01b3406b to your computer and use it in GitHub Desktop.
Save woodie/441b4457b0776406e890edff01b3406b to your computer and use it in GitHub Desktop.
name: Set new issues with Monday details
on:
issues:
types: [opened]
jobs:
set-new-issues-with-monday-details:
runs-on: ubuntu-latest
steps:
- id: title
run: echo "::set-output name=escaped::$(echo $title | sed -e 's/\"/\\\\\"/g')"
env:
title: |
${{ github.event.issue.title }}
- id: query
run: echo "::set-output name=query::$(echo $query | sed -e 's/\"/\\\"/g')"
env:
query: |
{ items_by_column_values(board_id: ${{ secrets.MONDAY_BOARD }}, column_id: "name", column_value: "${{ steps.title.outputs.escaped }}")
{ id creator { id name } column_values(ids: [github_issue]) { value } updates(limit: 1) { body } } }
- id: response
uses: satak/webrequest-action@master
with:
url: https://api.monday.com/v2
method: POST
headers: '{"Content-Type": "application/json", "Authorization": "${{ secrets.MONDAY_TOKEN }}"}'
payload: '{"query": "${{ steps.query.outputs.query }}"}'
- id: parse
run: |
echo "::set-output name=author_id::$(echo ${{ fromJson(steps.response.outputs.output).data.data.items_by_column_values[0].creator.id }})"
echo "::set-output name=author_name::$(echo ${{ fromJson(steps.response.outputs.output).data.data.items_by_column_values[0].creator.name }})"
echo "::set-output name=item_number::$(echo ${{ fromJson(steps.response.outputs.output).data.data.items_by_column_values[0].id }})"
echo "::set-output name=issue_number::$(echo ${{ fromJson(fromJson(steps.response.outputs.output).data.data.items_by_column_values[0].column_values[0].value).number }})"
- id: format
run: |
echo "::set-output name=head::$(echo $template | sed -e 's/\n/ /g')"
echo "::set-output name=body::$(echo $textbody | sed -e 's/\n/ /g' | sed -e 's/\"/\\\"/g' | sed -e 's/<img[^>]*>//g')"
env:
template: |
<p align=\"right\"><kbd align=\"left\"><b>Author </b><br/><a
href=\"https://${{ secrets.MONDAY_PREFIX }}.monday.com/boards/${{ secrets.MONDAY_BOARD }}?userId=${{ steps.parse.outputs.author_id }}\">${{ steps.parse.outputs.author_name }}</a></kbd> <kbd
align=\"left\"><a href=\"https://${{ secrets.MONDAY_PREFIX }}.monday.com/boards/${{ secrets.MONDAY_BOARD }}/pulses/${{ steps.parse.outputs.item_number }}\"><img
align=\"right\" height=\"18\" src=\"https://logowiki.net/uploads/logo/m/monday-1.svg\">Monday<br/> Item</a></kbd></p>
textbody: |
${{ fromJson(steps.response.outputs.output).data.data.items_by_column_values[0].updates[0].body }}
- if : ${{ contains(github.event.issue.body, 'via monday.com integration') && steps.parse.outputs.issue_number == github.event.issue.number }}
uses: satak/webrequest-action@master
with:
url: ${{ github.event.issue.url }}
method: PATCH
headers: '{"Accept": "application/vnd.github.v3+json", "Authorization": "Bearer ${{ secrets.GITHUB_TOKEN }}"}'
payload: '{"body": "${{ steps.format.outputs.head }}\n\n${{ steps.format.outputs.body }}"}'
- if : ${{ contains(github.event.issue.body, 'via monday.com integration') && steps.parse.outputs.issue_number != github.event.issue.number }}
uses: satak/webrequest-action@master
with:
url: ${{ github.event.issue.url }}
method: PATCH
headers: '{"Accept": "application/vnd.github.v3+json", "Authorization": "Bearer ${{ secrets.GITHUB_TOKEN }}"}'
payload: '{"body": "Duplicate Issue.", "state": "closed"}'
@woodie
Copy link
Author

woodie commented Apr 29, 2021

Monday.com provides in Integration that creates a Github Issue associated with a Monday Item. This workflow will update the Issue with a button (linking back to the Monday Item) and set the last Monday comment as the Issue body.

In your Github secrets, you should not need to set GITHUB_TOKEN but you will need:

  • MONDAY_BOARD — the Monday board number (repo-level secret)
  • MONDAY_PREFIX — the name that prepends your Monday instance (org-level secret)
  • MONDAY_TOKEN — the Monday API token (org-level secret)

example

stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment