Created
January 8, 2018 21:35
-
-
Save d2lam/6d8b5883ca0aaf5a7757333d6ec9546e to your computer and use it in GitHub Desktop.
Syncing webhooks for all projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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