auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
// This step pulls all Github issues reactions, for all open issues,
// for the target repo, overwriting the data in the Google Sheet
// each run. This is slightly inefficient, but the Github
// reactions API endpoint has no way to filter reactions by date.
// Moreover, if only sent new reactions to Google sheets, we'd have a lot
// of reactions to issues that were closed. Pulling only reactions for
// currently-opened issues removes this concern
const format = require('date-fns/format')
const parseISO = require('date-fns/parseISO')
// See https://octokit.github.io/rest.js/#automatic-retries
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: auths.github.oauth_access_token,
previews: ["squirrel-girl-preview"], // See https://developer.github.com/v3/previews/#reactions
throttle: {
onRateLimit: () => true,
onAbuseLimit: () => true,
}
})
const { owner, repo } = params
// List all the issues for our target repo, letting the
// octokit package handle pagination:
// https://octokit.github.io/rest.js/#pagination
//
// For params you can pass to the listForRepo method, see
// https://octokit.github.io/rest.js/#octokit-routes-issues
let options = octokit.issues.listForRepo.endpoint.merge({
owner,
repo,
})
const issues = await octokit.paginate(options)
this.issueCount = issues.length
this.sampleIssue = issues[0]
this.reactions = [['Repo Owner', 'Repo', 'Issue Title', 'URL', 'Opened By', 'Issue Created At', 'Reaction At', 'Reaction Type', 'Reaction By']]
const reactionRequests = []
for (const issue of issues) {
// List the reactions for our issue and add the relevant
// data for each reaction and associated issue to a list. See
// https://octokit.github.io/rest.js/#octokit-routes-reactions
options = octokit.reactions.listForIssue.endpoint.merge({
owner,
repo,
issue_number: issue.number,
})
reactionRequests.push(octokit.paginate(options))
}
// Make requests for all reactions in parallel to speed up
// the data retrieval. octokit should handle rate limiting 🤞
const reactionResponses = await Promise.all(reactionRequests)
for (const [index, reactions] of reactionResponses.entries()) {
if (!reactions.length) {
continue
}
// Reaction responses are in the same order as the issues tied
// to the reaction request. Grab the issue metadata from the same
// index of the issues array
const issue = issues[index]
for (const reaction of reactions) {
const { content, created_at } = reaction
this.reactions.push([
owner,
repo,
issue.title,
issue.url,
issue.user.login,
format(parseISO(issue.created_at), 'MM/dd/yyyy'),
format(parseISO(created_at), 'MM/dd/yyyy'),
content,
reaction.user.login,
])
}
}
auths
objectThe A1 notation of the values to update, including the sheet to update. For example: “Sheet1!A1:B2”
The ID of the spreadsheet to retrieve data from (found in the URL at docs.google.com/spreadsheets/d/{id})
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const data = {
range: params.range,
}
const config = {
method: "post",
url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.range}:clear`,
headers: {
Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
},
}
return await require("@pipedreamhq/platform").axios(this, config)
The A1 notation of the values to update, including the sheet to update. For example: “Sheet1!A1:B2”
The array of new values to update the sheet with. Google Sheets requires an array of arrays here, representing the grid of values you'd like to update in your sheet (see the docs for more information).
The ID of the spreadsheet to retrieve data from (found in the URL at docs.google.com/spreadsheets/d/{id})
async
(params, auths) => {
}
const data = {
range: params.range,
values: params.values,
majorDimension: params.majorDimension,
}
const config = {
method: "put",
url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.range}`,
params: {
includeValuesInResponse: params.includeValuesInResponse,
responseDateTimeRenderOption: params.responseDateTimeRenderOption,
responseValueRenderOption: params.responseValueRenderOption,
valueInputOption: params.valueInputOption || 'USER_ENTERED',
},
headers: {
Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
},
data,
}
return await require("@pipedreamhq/platform").axios(this, config)