Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gatherTransitions(issues, cb) {
- //for each issue, it goes through the transitions and sends them to an array.
- //Could probably be coupled with the next function..
- var transitionOptions = [];
- async.each(issues, function (issue, callback) {
- jira.listTransitions(issue.key, function (error, transitions) {
- if (error) {
- console.log("Error");
- callback(error);
- cb(error, null);
- return;
- } else {
- var object = {
- issue: issue.key,
- summary: issue.fields.summary,
- description: issue.fields.description,
- transitions: transitions.transitions
- };
- transitionOptions.push(object);
- callback(null);
- }
- });
- },
- function (err) {
- if (err) {
- console.log("An error in gatherTransitions".red);
- } else {
- cb(null, transitionOptions)
- }
- })
- }
- function removeUnnecessaryTransitions(issues, cb) {
- //Removes all transitions, so the release note is clean.
- //Sends the appropriate releases to 'toClose' array
- var toClose = [];
- _.each(issues, function (issue, iterator) {
- _.each(issue.transitions, function (transition) {
- var goodIssue = {
- key: null,
- summary: null,
- description: null,
- transitionDetails: null
- };
- if (transition.name === req.body.transition) {
- goodIssue.key = issue.issue;
- goodIssue.summary = issue.summary;
- goodIssue.description = issue.description;
- goodIssue.transitionDetails = transition;
- toClose.push(goodIssue);
- }
- });
- });
- return cb(null, toClose);
- }
- function transitionJiras(issues, cb) {
- //Transitions all Jiras in the issues array (toClose from above function).
- //Callback sent with the same issues passed to this function.
- async.each(issues, function (issue, callback) {
- var issueData = {
- update: {
- comment: [{add: {body: req.body.note}}]
- },
- fields: {
- resolution: {
- name: req.body.resolution
- }
- },
- transition: {
- id: issue.transitionDetails.id
- }
- };
- jira.transitionIssue(issue.key, issueData, function (error, result) {
- if (error) {
- console.log("Error from transitionIssue".red);
- console.log(error);
- callback(error);
- } else {
- callback(null);
- }
- })
- },
- function (err) {
- if (err) {
- console.log(err);
- cb(err);
- } else {
- cb(null, issues);
- }
- });
- }
- function closeVersions(issues, cb) {
- //Closes each version in req.body.versions array.
- //TODO: Add close date.
- //Callback sent with same issues.
- async.each(req.body.versions, function(version, callback) {
- var versionInfo = {
- id: version,
- released: true
- };
- jira.updateVersion(versionInfo, function(error, done) {
- if(error) {
- console.log(error);
- } else {
- callback(null);
- }
- })
- }, function(err) {
- if(err) {
- console.log(err)
- } else {
- cb(null, issues);
- }
- })
- }
- function sendReleaseNote(issues, cb) {
- //TODO: Send release note, cb with email note of time and issues.
- //TODO: in res.send, send email stamp AND issues to display on site.\
- mailer.sendRelease(issues, req.body.mail.gmail, req.body.mail.recipients, function(note) {
- cb(null, issues, note);
- })
- }
- function returnNotes(err, issues, notes) {
- if(err) {
- console.log(err);
- } else {
- console.log(notes);
- res.send(issues);
- }
- }
- var tasks = [
- searchJiras,
- gatherTransitions,
- removeUnnecessaryTransitions,
- transitionJiras,
- closeVersions,
- sendReleaseNote
- ];
- async.waterfall(tasks, returnNotes);
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement