Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
name: Weekly Issues Report
on:
schedule:
# Runs at 9AM UTC every Monday
- cron: '0 9 * * 1'
jobs:
GetIssues:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@0.3.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// import fetch
const fetch = require("node-fetch")
// Set the repo url
const repoUrl = `https://github.com/${{ github.repository }}`
// Variable to to hold the object to send to Flow
let issuesObjToSend = {}
// Variable to hold the issues that are required
let requiredIssues = []
// Label on which issues need to be filtered e.g. bug, question etc
const filterLabel = 'bug'
// State of the issue that need to be filtered
const filterState = 'open'
// GitHub URL which shows the filtered issues
const filteredIssuesUrl = `${repoUrl}/issues?q=is:issue is:${filterState} label:${filterLabel}`
// Subject of the message that will be posted in Teams
const subject = `List of issues labelled as ${filterLabel} that are open`
// URL of the HTTP triggered Flow
const flowUrl = "Enter the FLow HTTP POST URL copied"
// Build the options to get the required issues
const opts = github.issues.listForRepo.endpoint.merge({
...context.issue,
state: filterState,
labels: filterLabel
})
// Get the issues based on options
const issues = await github.paginate(opts)
// Build the requiredIssues object
for (const issue of issues) {
requiredIssues.push({
title: issue.title,
body: issue.body.substring(0,100) + "...",
url: issue.html_url,
assignedTo: issue.assignee.login,
assignedToPic: issue.assignee.avatar_url
})
}
// Create the notification text that the user will see in their mobile
const notificationText = `There are ${requiredIssues.length} issues marked as ${filterLabel} that are ${filterState} this week.`
// Build the object to send to the Flow
issuesObjToSend = { githubUrl: filteredIssuesUrl, issues: requiredIssues, subject: subject, notificationText: notificationText }
// Call the Flow
await fetch(flowUrl, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(issuesObjToSend)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment