31
Workflow Nel

Workflow && t1k

Embed Size (px)

Citation preview

Workflow Nel

Cartões são cadastrados no trello

Criamos uma issue no github

Incluimos no comentário do commit, o #código da issue

hack && ship

(Hashrocket)

http://reinh.com/blog/2008/08/27/hack-and-and-ship.htmlFonte:

t1k

t1k:hack

rake t1k:hack[E7lUvZ6Y]

~/W/w/matanza2_test git:master ❯❯❯ rake t1k:hack[E7lUvZ6Y]

Catching card

Creating issue

Updating card

Card #17 created and tracked

Already on 'master'

Your branch is up-to-date with 'origin/master'.

From github.com:rodrigomaia/matanza2_test

* branch master -> FETCH_HEAD

Current branch master is up to date.

Switched to a new branch '17'

~/W/w/matanza2_test git:17 ❯❯❯

t1k:commit

rake t1k:commit['criando método de teste',close]

~/W/w/matanza2_test git:17 ❯❯❯ rake t1k:commit['criando método de teste',close]

[17 c2de9eb] [close #17] criando método de teste

1 file changed, 3 insertions(+)

t1k:sink

rake t1k:sink

~/W/w/matanza2_test git:17 ❯❯❯ rake t1k:sink

Switched to branch 'master'

Your branch is up-to-date with 'origin/master'.

From github.com:rodrigomaia/matanza2_test

* branch master -> FETCH_HEAD

Current branch master is up to date.

Switched to branch '17'

Already on '17'

Current branch 17 is up to date.

t1k:ship

rake t1k:ship

~/W/w/matanza2_test git:17 ❯❯❯ rake t1k:ship ✭

Switched to branch 'master'

Your branch is up-to-date with 'origin/master'.

Current branch master is up to date.

Updating bfae756..c2de9eb

Fast-forward

app/models/notum.rb | 3 +++

1 file changed, 3 insertions(+)

On branch master

Your branch is ahead of 'origin/master' by 1 commit.

(use "git push" to publish your local commits)

nothing to commit, working directory clean

Counting objects: 5, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (5/5), done.

Writing objects: 100% (5/5), 480 bytes | 0 bytes/s, done.

Total 5 (delta 3), reused 0 (delta 0)

To [email protected]:rodrigomaia/matanza2_test.git

bfae756..c2de9eb master -> master

~/W/w/matanza2_test git:master ❯❯❯

Como usar?

gem 't1k'

14

15 T1k.configure do |config|

16 config[:github_user] = 'rodrigomaia'

17 config[:github_repo] = 'matanza2_test'

18 config[:github_oauth_token] = ENV["GITHUB_TOKEN"]

19 config[:trello_developer_public_key] = ENV["TRELLO_KEY"]

20 config[:trello_member_token] = ENV["TRELLO_TOKEN"]

21 config[:trello_user_name] = 'rudrige'

22 config[:trello_board_name] = 't1k'

23 end

Código do t1k

1 require 'rake'

2

3 # rake t1k:hack['uD2GBBMf']

4 namespace :t1k do

5 desc "Cria issue e atualiza cartão do trello"

6

7 task :hack, [:path_card_part] do |t, args|

8 code_card = T1k::hack args[:path_card_part]

9

10 system 'git checkout master'

11 system 'git pull --rebase origin master'

12 system "git checkout -b #{code_card}"

13 end

14 end

1 require 'rake'

2

3 #rake t1k:commit['comentario do commit',close]

4 namespace :t1k do

5 desc "Commita com a info da issue para vincular ao github"

6

7 task :commit, [:comment, :close] do |t, args|

8 closed = args[:close] == 'close' ? "close " : ""

9 branch = `git branch | grep '*' | awk '{print $2}'`

10 system "git commit -m '[#{closed}##{branch.strip}] #{args[:comment]}'"

11 end

12 end

1 require 'rake'

2

3 #rake t1k:sink

4 namespace :t1k do

5 desc "Sincroniza branch atual com o master"

6

7 task :sink do |t, args|

8 branch = `git branch | grep '*' | awk '{print $2}'`

9 system "git checkout master"

10 system "git pull --rebase origin master"

11 system "git checkout #{branch.strip}"

12 system "git rebase master #{branch.strip}"

13 end

14 end

1 require 'rake'

2

3 #rake t1k:ship

4 namespace :t1k do

5 desc "Faz merge com o master e pusha"

6

7 task :ship do |t, args|

8 branch = `git branch | grep '*' | awk '{print $2}'`

9 system "git checkout master"

10 system "git pull --rebase"

11 system "git merge #{branch.strip}"

12 system "git commit -v"

13 system "git push origin master"

14 end

15 end

1 require "t1k/engine"

2 require "trello"

3 require "github_api"

4

5 module T1k

6 @@config = {}

7

8 def self.configure &block

9 block.call @@config

10 config_trello

11 config_github

12 end

13

14 def self.hack url_card

15 card = get_card url_card

16 issue = create_issue card.name

17 code_issue = get_issue_code issue

18

19 update_card card, code_issue

20 puts "Card ##{code_issue[:code]} created and tracked"

21 code_issue[:code]

22 end

23

24 private

25

26 def self.get_card url_card

27 begin

28 puts "Catching card"

29 me = Trello::Member.find(@@config[:trello_user_name])

30 board = me.boards.select{|x| x.name.upcase == @@config[:trello_board_name].upcase}.first

31 card = board.cards.select{|x| x.url.index(url_card)}.first

32 raise if card.nil?

33

34 card

35 rescue

36 raise 'Card not found'

37 end

38 end

39

40 def self.update_card card, issue_code

41 puts "Updating card"

42 card.name = "[##{issue_code[:code]}] #{card.name}"

43 card.desc = "#{issue_code[:link]} #{card.desc}"

44 card.save

45 end

46

47 def self.create_issue title

48 begin

49 puts "Creating issue"

50 github_auth = Github.new :oauth_token => @@config[:github_oauth_token]

51 github_auth.issues.create user: @@config[:github_user], repo: @@config[:github_repo], title: title

52 rescue

53 raise 'Issue not created'

54 end

55 end

56

57 def self.get_issue_code issue

58 url_issue = issue.html_url

59 code = url_issue[url_issue.rindex('/')+1..url_issue.size]

60 code_html_issue = {code: code,link: "Link to code: [#{code}](#{url_issue})”}

61

62 end

63

64 def self.config_trello

68 Trello.configure do |config|

69 config.developer_public_key = @@config[:trello_developer_public_key]

70 config.member_token = @@config[:trello_member_token]

71 end

72 end

73

74 def self.config_github

77 end

78 end

https://github.com/fortesinformatica/t1k

https://rubygems.org/gems/t1k

[ t1k ]