Skip to content

Instantly share code, notes, and snippets.

@d2lam
Created January 8, 2018 21:35
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 d2lam/6d8b5883ca0aaf5a7757333d6ec9546e to your computer and use it in GitHub Desktop.
Save d2lam/6d8b5883ca0aaf5a7757333d6ec9546e to your computer and use it in GitHub Desktop.
Syncing webhooks for all projects
/** Need to configure API_URL and USER_TOKEN
*/
'use strict';
const Promise = require('promise');
const request = require('request-promise');
const API_URL = 'https://beta.api.screwdriver.cd/v4/pipelines';
const USER_TOKEN = process.env.USER_TOKEN;
const getPipelinesOptions = {
method: 'GET',
uri: API_URL,
json: true
};
const syncWebhooksOptions = {
method: 'POST',
auth: {
bearer: USER_TOKEN
},
json: true
};
return request(getPipelinesOptions)
.then((pipelines) => {
const toSync = [];
pipelines.forEach((p) => {
console.log('Need to sync pipelineId ', p.id);
syncWebhooksOptions.uri = `${API_URL}/${p.id}/sync/webhooks`;
toSync.push(request(syncWebhooksOptions));
});
return Promise.all(toSync);
})
.then(() => console.log('Done'))
.catch(err => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment