Skip to content

Instantly share code, notes, and snippets.

@d2lam
Last active January 17, 2018 01:48
Show Gist options
  • Save d2lam/bb05a5c909b8061ec4bff142b734822b to your computer and use it in GitHub Desktop.
Save d2lam/bb05a5c909b8061ec4bff142b734822b to your computer and use it in GitHub Desktop.
'use strict';
const API_URL = 'https://beta.api.screwdriver.cd/v4';
const Models = require('screwdriver-models');
// Setup Datastore
const datastoreConfig = config.get('datastore');
const DatastorePlugin = require(`screwdriver-datastore-${datastoreConfig.plugin}`);
const datastore = new DatastorePlugin(datastoreConfig[datastoreConfig.plugin]);
// Source Code Plugin
const scmConfig = { scms: config.get('scms') };
const ScmPlugin = require('screwdriver-scm-router');
const scm = new ScmPlugin(scmConfig || {});
const pipelineFactory = Models.PipelineFactory.getInstance({
datastore,
scm
});
const scmContexts = pipelineFactory.scm.getScmContexts();
const authConfig = config.get('auth');
const userFactory = Models.UserFactory.getInstance({
datastore,
scm,
password: authConfig.encryptionPassword
});
let pipelineArray = [];
scmContexts.forEach((scmContext) => {
const pipelines = pipelineFactory.list({
params: {
scmContext
},
paginate: {
page: request.query.page,
count: request.query.count
},
sort: request.query.sort
});
pipelineArray = pipelineArray.concat(pipelines);
});
return Promise.all(pipelineArray)
.then(pipelineArrays => [].concat(...pipelineArrays))
.then((pipelines) => {
const toSync = [];
let admin;
let syncFunc;
pipelines.forEach(p => toSync.push(p.addWebhook(`${API_URL}/pipelines`)));
return Promise.all(toSync);
})
.then(() => console.log('Done'))
.catch(err => console.log(err));
@minzcmu
Copy link

minzcmu commented Jan 17, 2018

'use strict';

const API_URL = 'https://beta.api.screwdriver.cd/v4';
const Models = require('screwdriver-models');
const config = require('config');

// Setup Datastore
const datastoreConfig = config.get('datastore');
const DatastorePlugin = require(`screwdriver-datastore-${datastoreConfig.plugin}`);
const datastore = new DatastorePlugin(datastoreConfig[datastoreConfig.plugin]);

// Source Code Plugin
const scmConfig = { scms: config.get('scms') };
const ScmPlugin = require('screwdriver-scm-router');
const scm = new ScmPlugin(scmConfig || {});
const pipelineFactory = Models.PipelineFactory.getInstance({
    datastore,
    scm
});
const scmContexts = pipelineFactory.scm.getScmContexts();
const authConfig = config.get('auth');
const userFactory = Models.UserFactory.getInstance({
    datastore,
    scm,
    password: authConfig.encryptionPassword
});

let pipelineArray = [];

scmContexts.forEach((scmContext) => {
  const pipelines = pipelineFactory.list({
      params: {
          scmContext
      },
      paginate: {
          page: 1,
          count: 50
      }
  });

  pipelineArray = pipelineArray.concat(pipelines);
});

return Promise.all(pipelineArray)
    .then(pipelineArrays => [].concat(...pipelineArrays))
    .then((pipelines) => {
        const toSync = [];
        let admin;
        let syncFunc;
        pipelines.forEach(p => console.log(p.id));
        pipelines.forEach(p => toSync.push(p.addWebhook(`${API_URL}/pipelines`)));

        return Promise.all(toSync);
    })
    .then(() => console.log('Done'))
    .catch(err => console.log(err));

@minzcmu
Copy link

minzcmu commented Jan 17, 2018

{
  "name": "test-webhook",
  "version": "1.0.0",
  "description": "",
  "main": "addWebhook.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "config": "^1.29.2",
    "screwdriver-datastore-sequelize": "^4.0.3",
    "screwdriver-models": "^26.6.1",
    "screwdriver-scm-github": "^5.1.4",
    "screwdriver-scm-router": "^1.0.2"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment