Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// push changes back to GitHub
await execa('git', ['checkout', '-b', branchName])
await execa('git', ['add', 'cache'])
await execa('git', ['commit', '-m', 'build: cache'])
await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', 'build: webhooks'])
await execa('git', [
'push',
`https://${process.env.GH_TOKEN}@github.com/${owner}/${repo}.git`,
`HEAD:${branchName}`
])
await execa('git', ['checkout', '-'])
// start pullrequest
const { body } = await request('POST /repos/:owner/:repo/pulls', {
owner,
repo,
headers: {
authorization: `token ${process.env.GH_TOKEN}`
},
title: `🤖🚨 ${changesSummary}`,
head: branchName,
base: 'master',
body: `Dearest humans,
My friend Travis asked me to let you know that they found webhook changes in their daily routine check.`
})
console.log(`🤖 Pull request created: ${body.html_url}`)
}
function loadFixture(scenario) {
return request("POST http://localhost:3000/fixtures", {
data: JSON.stringify({ scenario })
})
.then(response => response.data)
.catch(error => {
if (error.status === "ECONNREFUSED") {
throw new Error(
'Fixtures server could not be reached. Make sure to start it with "npm run start-fixtures-server"'
);
}
throw error;
});
}
async function getHtml (state) {
const cacheFilePath = 'event-types-and-payloads.html'
if (state.cached && await cache.exists(cacheFilePath)) {
return cache.read(cacheFilePath)
}
console.log(`⌛ fetching ${WEBHOOKS_DOCS_URL}`)
const { data: html } = await request(WEBHOOKS_DOCS_URL)
await cache.writeHtml(cacheFilePath, html)
return html
}
const cached_signature = get_cached_etag(url, request_signature);
if (cached_signature != null) {
request_headers['If-None-Match'] = cached_signature;
}
if (installationId == null) {
installationId = await get_installation_id(full_name);
db.installations.set_id(full_name, installationId);
}
try {
const installationAccessToken = await github_app.getInstallationAccessToken(
{ installationId },
);
const response = await request(url, {
...options,
headers: {
...request_headers,
authorization: `token ${installationAccessToken}`,
},
});
const { etag } = response.headers;
REQUEST_SIGNATURES[url][request_signature] = etag;
return response;
} catch (e) {
return e;
}
};
async _authenticate (username, repository) {
const app = new App(
{
id: config.get('githubAppID'),
privateKey: config.get('githubPrivateKey'),
baseUrl: config.get('githubBaseUrl')
}
)
const jwt = app.getSignedJsonWebToken()
const {data} = await request('GET /repos/:owner/:repo/installation', {
owner: username,
repo: repository,
headers: {
authorization: `Bearer ${jwt}`,
accept: 'application/vnd.github.machine-man-preview+json'
}
})
const installationId = data.id
let token = await app.getInstallationAccessToken({installationId})
return token
}