Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Prebuild parse and test .apphub file
  3.  */
  4. import Promise from 'bluebird';
  5. import Hubkit from 'hubkit';
  6. import AppHook from '~/appHooks/appHook';
  7.  
  8. const gh = new Hubkit();
  9. let hook = new AppHook('apphub');
  10.  
  11. let apphub = {};
  12.  
  13. hook.question(release => {
  14.   const application = release.ownerDocument();
  15.  
  16.   return gh.request(`GET /repos/${application.github.fullName}/contents/.apphub`, {
  17.     token: application.github.APItoken,
  18.   })
  19.   .then(apphubData => {
  20.     try {
  21.       const apphubBase = new Buffer(apphubData.content, 'base64');
  22.       apphub = JSON.parse(apphubBase.toString());
  23.     } catch (err) {
  24.       hook.error('parse');
  25.       return Promise.reject();
  26.     }
  27.  
  28.     return Promise.resolve();
  29.   });
  30. });
  31.  
  32. hook.question(release => {
  33.   if (typeof apphub.priceUSD != 'undefined' && typeof apphub.priceUSD != 'number') {
  34.     hook.error('price');
  35.   } else if (apphub.priceUSD != null) {
  36.     hook.update({priceUSD: apphub.priceUSD});
  37.   }
  38.  
  39.   return Promise.resolve();
  40. });
  41.  
  42. hook.question(release => {
  43.   if (typeof apphub.issueLabel != 'undefined' && typeof apphub.issueLabel != 'string') {
  44.     hook.error('label');
  45.   } else if (apphub.issueLabel != null) {
  46.     hook.update({github: {label: apphub.issueLabel}});
  47.   }
  48.  
  49.   return Promise.resolve();
  50. });
  51.  
  52. export default hook
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement