Skip to content

Instantly share code, notes, and snippets.

@anoopt
Last active December 14, 2019 18:41
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 anoopt/6dd7765ca55ab3053e0025c26179eba6 to your computer and use it in GitHub Desktop.
Save anoopt/6dd7765ca55ab3053e0025c26179eba6 to your computer and use it in GitHub Desktop.
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