Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pit('should reject if `got` has rejected', () => {
mock_got.mockReturnValueOnce(Promise.resolve(null));
return searchClient.findCompatiblePackages('fakeBackend', []).then(
(ret) => {
throw new Error('Promise should not be resolved');
},
(err) => {
// done
}
);
});
});
async updateReleasesList() {
var shouldUpdate = false;
var ElectronReleaseData;
var remoteEtag;
var localEtag;
if (!shouldUpdate) {
var releaseFile = fs.readdirSync(this.releasesFilePath).filter(fn => fn.startsWith('releases.'));
if (releaseFile.length > 0) { // file exists, we should check the etag
try {
ElectronReleaseData = await got.head('https://raw.githubusercontent.com/electron/releases/master/index.json');
} catch (e) {
console.log(chalk.yellow(`Something went wrong while fetching Electron's releases. No connectivity?`));
return false;
}
var rawRemoteEtag = ElectronReleaseData.headers.etag;
remoteEtag = rawRemoteEtag.match(this.githubEtagRegex);
if (remoteEtag == null) {
console.log(chalk.yellow(`Something went wrong while fetching Electron's releases. Etag returned from Github was not recognized.`));
return false;
} else remoteEtag = remoteEtag[0];
localEtag = releaseFile[0].split('.')[1];
//check if it corresponds to our local version
if (localEtag === remoteEtag)
shouldUpdate = false;
else {
public openTranscript(protocol: Protocol): void {
const { url } = protocol.parsedArgs;
const options = { url };
return got(options)
.then(res => {
if (/^2\d\d$/.test(res.statusCode)) {
if (res.body) {
try {
// parse the activities from the downloaded transcript
const transcriptString = res.body;
const conversationActivities = JSON.parse(transcriptString);
if (!Array.isArray(conversationActivities)) {
throw new Error('Invalid transcript file contents; should be an array of conversation activities.');
}
const { name, ext } = Path.parse(url);
const fileName = `${name}${ext}`;
// open a transcript on the client side and pass in some
// extra info to differentiate it from a transcript on disk
this.commandService.remoteCall(SharedConstants.Commands.Emulator.OpenTranscript, 'deepLinkedTranscript', {
activities: conversationActivities,
function token(event, context) {
const EARTHDATA_CLIENT_ID = process.env.EARTHDATA_CLIENT_ID;
const EARTHDATA_CLIENT_PASSWORD = process.env.EARTHDATA_CLIENT_PASSWORD;
const EARTHDATA_BASE_URL = process.env.EARTHDATA_BASE_URL || 'https://uat.urs.earthdata.nasa.gov';
const EARTHDATA_CHECK_CODE_URL = `${EARTHDATA_BASE_URL}/oauth/token`;
const code = get(event, 'queryStringParameters.code');
const state = get(event, 'queryStringParameters.state');
// Code contains the value from the Earthdata Login redirect. We use it to get a token.
if (code) {
const params = `?grant_type=authorization_code&code=${code}&redirect_uri=${redirectUriParam()}`;
// Verify token
return got.post(EARTHDATA_CHECK_CODE_URL + params, {
json: true,
auth: `${EARTHDATA_CLIENT_ID}:${EARTHDATA_CLIENT_PASSWORD}`
}).then((r) => {
const tokenInfo = r.body;
const accessToken = tokenInfo.access_token;
// if no access token is given, then the code is wrong
if (typeof accessToken === 'undefined') {
return resp(context, new Error('Failed to get Earthdata token'));
}
const refresh = tokenInfo.refresh_token;
const userName = tokenInfo.endpoint.split('/').pop();
const expires = (+new Date()) + (tokenInfo.expires_in * 1000);
const u = new User();
'use strict'
const { expect } = require('chai')
// https://github.com/nock/nock/issues/1523
const got = require('got').extend({ retry: 0 })
const isSvg = require('is-svg')
let server
before(function() {
this.timeout('5s')
// remove args comming from mocha
// https://github.com/badges/shields/issues/3365
process.argv = []
server = require('./server')
})
after('shut down the server', async function() {
await server.stop()
})
it('should render a badge', async function() {
try {
let response = await got.post('http://localhost:3000/beams', { // eslint-disable-line no-unused-vars
body: wavFmt.toJSON(),
json: true,
headers : { 'Content-Type': 'application/json' }
}).catch(err => {
if (err.statusCode === 409) {
console.log('Got conflict: assuming OK.');
} else {
throw err;
}
});
let pkt = await wavFmt.read();
for ( ; pkt != null ; pkt = await wavFmt.read()) {
await got.put(`http://localhost:3000/beams/${locPathPart}/stream_0/packet_${pkt.pts}`, {
body: pkt.toJSON(),
json: true
});
await got.put(
`http://localhost:3000/beams/${locPathPart}/stream_0/packet_${pkt.pts}/data`, {
body: pkt.data,
headers: { 'Content-Type': 'application/octet-stream' }
});
}
} catch (err) {
console.error(err.stack);
}
}
const create = () => got.create({
options: got.mergeOptions(got.defaults.options, {
json: true,
token: process.env.GITHUB_TOKEN,
baseUrl: process.env.GITHUB_ENDPOINT || 'https://api.github.com',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'https://github.com/sindresorhus/gh-got'
}
}),
methods: got.defaults.methods,
handler: (options, next) => {
if (options.token) {
options.headers.authorization = options.headers.authorization || `token ${options.token}`;
}
if (options.stream) {
return next(options);
}
// TODO: Use async/await here when Got supports the `handler` being an async function
return next(options)
.then(response => { // eslint-disable-line promise/prefer-await-to-then
response.rateLimit = getRateLimit(response);
return response;
})
instrument(metrics.gitserverDurationHistogram, metrics.gitserverErrorsCounter, async () => {
// Perform request - this may fail with a 404 or 500
const resp = await got(new URL(`http://${gitserverUrl}/exec`).href, {
body: JSON.stringify({ repo: repository, args }),
})
// Read trailers on a 200-level response
const status = resp.trailers['x-exec-exit-status']
const stderr = resp.trailers['x-exec-stderr']
// Determine if underlying git command failed and throw an error
// in that case. Status will be undefined in some of our tests and
// will be the process exit code (given as a string) otherwise.
if (status !== undefined && status !== '0') {
throw new Error(`Failed to run git command ${['git', ...args].join(' ')}: ${stderr}`)
}
return resp.body
})
if (playlistName === undefined){
playlistName = response.body.name;
}
// holds playlist tracks
let tracks = responseTracks.map(responseTrack => responseTrack.track.uri)
var createPlaylistOptions = {
json: true,
headers: {
'Content-type': 'application/json',
'Authorization' : `Bearer ${config.get('bearer')}`,
'Accept' : 'application/json'
},
body: JSON.stringify({ description: `spotiforked from ${playlistUser}/${forkedFrom}`, name: `${playlistName}`, public : true})
};
// create playlist
got.post(`https://api.spotify.com/v1/users/${config.get('username')}/playlists`, createPlaylistOptions)
.then(response => {
// get playlist ID
const newPlaylistID = response.body.id;
// function to add tracks to playlist
function populatePlaylist (id, uris, name) {
var url = `https://api.spotify.com/v1/users/${config.get('username')}/playlists/${id}/tracks?uris=${uris}`
var options = {
json: true,
headers: {
'Content-type': 'application/json',
'Authorization' : `Bearer ${config.get('bearer')}`,
}
};
got.post(url, options)
.then(response => {
paths('.tmp', 'pdf', filename).then(filepath => {
if (filepath.endsWith('.pdf')) {
got.stream(opts.url)
.pipe(fs.createWriteStream(filepath));
}
if (filepath.endsWith('.zip')) {
got.stream(opts.url)
.pipe(unzip.Extract({path: path.dirname(filepath)})); // eslint-disable-line new-cap
}
});
}