Last active
August 29, 2015 14:05
-
-
Save kerbyfc/1686c7b4865c6674689e to your computer and use it in GitHub Desktop.
Grunt таска для удаления всех локальных и удаленных git-веток с ссылками на закрытые Redmine-тикеты
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
grunt = require('grunt') | |
exec = require("child_process").exec | |
grunt.loadNpmTasks('grunt-shell') | |
request = require('request') | |
cheerio = require('cheerio') | |
grunt.registerTask 'check_status', (branch) -> | |
if branch = branch.replace(/^[\s]*|[\s]*$/, '') | |
done = @async() | |
ticket = branch.match(/[\d]{5,5}/g) | |
request "http://pm.undev.cc/issues/#{ticket}", (error, responce, body) -> | |
if error? | |
grunt.fail.warn error | |
else | |
if responce.statusCode is 200 | |
$ = cheerio.load(body) | |
status = $('td.status').first().text().toLowerCase() | |
grunt.log.writeln status | |
if status is "closed" | |
cmd = if branch.match(/^remotes/)? | |
"git push origin #{branch.replace(/^remotes\/origin\//, '')} --delete" | |
else | |
"git branch -d #{branch}" | |
exec cmd, (error, stdout, stderr) -> | |
if error? | |
grunt.fail.warn error | |
grunt.log.ok "#{cmd}" | |
grunt.log.writeln stdout | |
done() | |
else | |
grunt.fail.warn JSON.stringify(responce, null, 2) | |
done() | |
module.exports = -> | |
cookie = grunt.option 'cookie' | |
unless cookie | |
grunt.fail.fatal '--cookie option is required (_session_id cookie)' | |
grunt.option 'cookie', cookie | |
grunt.option 'force', true | |
j = request.jar() | |
j.setCookie("_session_id=#{cookie};", "http://pm.undev.cc") | |
grunt.log.writeln(JSON.stringify(j, null, 2)) | |
request = request.defaults({jar:j}) | |
grunt.initConfig | |
shell: | |
get_branches: | |
command: "git branch -a | grep '[0-9]\\{5,5\\}'" | |
options: | |
stdout: false | |
callback: (error, stdout, stderr, cb) -> | |
for branch in stdout.split(/\n[\s]*/) | |
if branch | |
do (branch) => | |
grunt.task.run "check_status:#{branch}" | |
cb() | |
grunt.task.run "shell:get_branches" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment