Module: Gitcycle::QA

Included in:
Gitcycle
Defined in:
lib/gitcycle/qa.rb

Instance Method Summary collapse

Instance Method Details

#qa(*issues) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/gitcycle/qa.rb', line 4

def qa(*issues)
  require_git && require_config

  if issues.empty?
    puts "\n"
    get('qa_branch').each do |branches|
      puts "qa_#{branches['source']}_#{branches['user']}".green
      branches['branches'].each do |branch|
        puts "  #{"issue ##{branch['issue']}".yellow}\t#{branch['user']}/#{branch['branch']}"
      end
      puts "\n"
    end
  elsif issues.first == 'fail' || issues.first == 'pass'
    branch = branches(:current => true)
    pass_fail = issues.first
    label = pass_fail.capitalize
    issues = issues[1..-1]

    if pass_fail == 'pass' && !issues.empty?
      puts "\nWARNING: #{
        issues.length == 1 ? "This issue" : "These issues"
      } will merge straight into '#{branch}' without testing.\n".red
      
      if yes?("Continue?")
        qa_branch = create_qa_branch(
          :instructions => false,
          :issues => issues,
          :source => branch
        )
        `git checkout qa_#{qa_branch['source']}_#{qa_branch['user']} -q`
        $remotes = {}
        qa('pass')
      else
        exit ERROR[:told_not_to_merge]
      end
    elsif branch =~ /^qa_/
      puts "\nRetrieving branch information from gitcycle.\n".green
      qa_branch = get('qa_branch', :source => branch.gsub(/^qa_/, ''))

      if pass_fail == 'pass'
        checkout_or_track(:name => qa_branch['source'], :remote => 'origin')
      end

      if issues.empty? 
        branches = qa_branch['branches']
      else
        branches = qa_branch['branches'].select do |b|
          issues.include?(b['issue'])
        end
      end

      if pass_fail == 'pass' && issues.empty?
        owner, repo = qa_branch['repo'].split(':')
        merge_remote_branch(
          :owner => owner,
          :repo => repo,
          :branch => "qa_#{qa_branch['source']}_#{qa_branch['user']}",
          :type => :from_qa
        )
      end

      unless issues.empty?
        branches.each do |branch|
          puts "\nLabeling issue #{branch['issue']} as '#{label}'.\n".green
          get('label',
            'qa_branch[source]' => qa_branch['source'],
            'issue' => branch['issue'],
            'labels' => [ label ]
          )
        end
      end

      if issues.empty?
        puts "\nLabeling all issues as '#{label}'.\n".green
        get('label',
          'qa_branch[source]' => qa_branch['source'],
          'labels' => [ label ]
        )
      end
    else
      puts "\nYou are not in a QA branch.\n".red
    end
  elsif issues.first == 'resolved'
    branch = branches(:current => true)

    if branch =~ /^qa_/
      puts "\nRetrieving branch information from gitcycle.\n".green
      qa_branch = get('qa_branch', :source => branch.gsub(/^qa_/, ''))
      
      branches = qa_branch['branches']
      conflict = branches.detect { |branch| branch['conflict'] }

      if qa_branch && conflict
        puts "Committing merge resolution of #{conflict['branch']} (issue ##{conflict['issue']}).\n".green
        run("git add . && git add . -u && git commit -a -F .git/MERGE_MSG")

        puts "Pushing merge resolution of #{conflict['branch']} (issue ##{conflict['issue']}).\n".green
        run("git push origin qa_#{qa_branch['source']}_#{qa_branch['user']} -q")

        puts "\nDe-conflicting on gitcycle.\n".green
        get('qa_branch',
          'issues' => branches.collect { |branch| branch['issue'] }
        )

        create_qa_branch(
          :preserve => true,
          :range => (branches.index(conflict)+1..-1),
          :qa_branch => qa_branch
        )
      else
        puts "Couldn't find record of a conflicted merge.\n".red
      end
    else
      puts "\nYou aren't on a QA branch.\n".red
    end
  else
    create_qa_branch(:issues => issues)
  end
end