git_game_show 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dd69e30776e28d63d3fd20db47716c0e957dace72788a5e0479047fe8cbe708
4
- data.tar.gz: cd8e8579ec722b25a67ffd1c8268f35a724dcf75cd863420ffebad9025f1ebf4
3
+ metadata.gz: 716f1e1333d827134e24ece60dd4d14762c72f7c67ba77d4041e3ed020234fc7
4
+ data.tar.gz: 94fbdf09cf6588a357ffdcb1722d97bd43afb97872c96904ed272539b4d36a54
5
5
  SHA512:
6
- metadata.gz: 8874ab5bb9a8349e9b22926e8456fef2aa1ce4bcdaf1ca14b170d82d6e0491a68db6c576eda153b92fbca942efa1861dd44d139d1d57e709fe2853e5c2b36fe6
7
- data.tar.gz: 37c9292edb46b4e3be1283efbd09b3762c504696a5d875a16c7d8a12fdbc68265319f40b4db992e0c4fd71d42bf420abcce75bd3e62402c741ba38e459c265a2
6
+ metadata.gz: f9ce22d13a247c04acc299bb0d4e988f00db8bddea9c30ff9102196dd2cd8df38accad3fb07368cae4e9deaa5d713729c89d55296fcf21a22afee4157d08b761
7
+ data.tar.gz: cd91d7b25ca66d04ff9bf53a399021a5adac70224799426401f284de41659a6a8e6909a9aeb430c0d64201faee881b0919a99ac41a6a1fbf1418b643e8abeb6e
@@ -1594,7 +1594,8 @@ module GitGameShow
1594
1594
  GitGameShow::AuthorQuiz,
1595
1595
  GitGameShow::FileQuiz,
1596
1596
  GitGameShow::CommitMessageCompletion,
1597
- GitGameShow::DateOrderingQuiz
1597
+ GitGameShow::DateOrderingQuiz,
1598
+ GitGameShow::BranchDetective
1598
1599
  ]
1599
1600
  end
1600
1601
  end
@@ -986,7 +986,7 @@ module GitGameShow
986
986
  box_width = 40
987
987
  puts "\n"
988
988
  puts ("╭" + "─" * box_width + "╮").center(@game_width).colorize(:yellow)
989
- puts "│#{'Scoreboard'.center(box_width)}".center(@game_width).colorize(:yellow)
989
+ puts "│#{'Scoreboard'.center(box_width)}".center(@game_width).colorize(:yellow)
990
990
  puts ("╰" + "─" * box_width + "╯").center(@game_width).colorize(:yellow)
991
991
  puts "\n"
992
992
 
@@ -1,4 +1,4 @@
1
1
  module GitGameShow
2
2
  # Current version of Git Game Show
3
- VERSION = "0.1.9"
3
+ VERSION = "0.1.10"
4
4
  end
@@ -0,0 +1,228 @@
1
+ module GitGameShow
2
+ class BranchDetective < MiniGame
3
+ self.name = "Branch Detective"
4
+ self.description = "Identify which branch a commit belongs to!"
5
+ self.questions_per_round = 5
6
+
7
+ # Custom timing for this mini-game
8
+ def self.question_timeout
9
+ 15 # 15 seconds per question
10
+ end
11
+
12
+ def self.question_display_time
13
+ 5 # 5 seconds between questions
14
+ end
15
+
16
+ def generate_questions(repo)
17
+ @repo = repo
18
+ begin
19
+ # Get all branches (both local and remote)
20
+ branches = {}
21
+
22
+ # Use Git command to get all local and remote branches
23
+
24
+ # get all remote branches from the git repository
25
+ all_remotes_cmd = "cd #{@repo.dir.path} && git branch -r"
26
+ all_branch_output = `#{all_remotes_cmd}`
27
+
28
+ # Parse branch names and clean them up
29
+ branch_names = all_branch_output.split("\n").map do |branch|
30
+ branch = branch.gsub(/^\* /, '').strip # Remove the * prefix from current branch
31
+
32
+ # Skip special branches like HEAD
33
+ next if branch == 'HEAD' || branch =~ /HEAD detached/
34
+
35
+ branch
36
+ end.compact.uniq # Remove nils and duplicates
37
+
38
+ # Filter out any empty branch names
39
+ branch_names.reject!(&:empty?)
40
+
41
+ # Need at least 3 branches to make interesting questions
42
+ if branch_names.size < 5
43
+ return generate_sample_questions
44
+ end
45
+
46
+ branch_names = branch_names.sample(100) if branch_names.size > 100
47
+
48
+ branch_names.each do |branch|
49
+ # Get commits for this branch
50
+ branches[branch] = get_commits_for_branch(branch)
51
+ end
52
+
53
+ # Generate questions
54
+ questions = []
55
+
56
+ self.class.questions_per_round.times do
57
+ # Select branches that have commits
58
+ branch_options = branch_names.sample(4)
59
+
60
+
61
+ # If we don't have 4 valid branches, pad with duplicates and ensure uniqueness later
62
+ if branch_options.size < 4
63
+ branch_options = branch_names.dup
64
+ while branch_options.size < 4
65
+ branch_options << branch_names.sample
66
+ end
67
+ end
68
+
69
+ # Choose a random branch as the correct answer
70
+ correct_branch = branch_options.sample
71
+
72
+ # Choose a random commit from this branch
73
+ commit = branches[correct_branch].sample
74
+
75
+ # Create the question
76
+ commit_date = commit[:date] #.split(" ")[0..2].join(" ") + " " + commit[:date].split(" ")[4]
77
+ commit_short_sha = commit[:sha][0..6]
78
+
79
+ # Format the commit message for display
80
+ message = commit[:message].lines.first&.strip || "No message"
81
+ message = message.length > 50 ? "#{message[0...47]}..." : message
82
+
83
+ questions << {
84
+ question: "Which branch was this commit originally made on?\n\n \"#{message}\"",
85
+ commit_info: "#{commit_short_sha} (by #{commit[:author]} on #{commit_date})",
86
+ options: branch_options.uniq.shuffle,
87
+ correct_answer: correct_branch
88
+ }
89
+ end
90
+
91
+ # If we couldn't generate enough questions, fill with sample questions
92
+ if questions.size < self.class.questions_per_round
93
+ sample_questions = generate_sample_questions
94
+ questions += sample_questions[0...(self.class.questions_per_round - questions.size)]
95
+ end
96
+
97
+ questions
98
+ rescue => e
99
+ # If any errors occur, fall back to sample questions
100
+ generate_sample_questions
101
+ end
102
+ end
103
+
104
+ # Generate sample questions
105
+ def generate_sample_questions
106
+ questions = []
107
+
108
+ # Sample data with branch names and commits
109
+ sample_branches = [
110
+ "main", "develop", "feature/user-auth", "bugfix/login",
111
+ "feature/payment", "hotfix/security", "release/v2.0", "staging"
112
+ ]
113
+
114
+ # Sample commit data
115
+ sample_commits = [
116
+ { message: "[SAMPLE] Add user authentication flow", author: "Jane Doe", date: "2023-05-15 14:30:22", sha: "a1b2c3d" },
117
+ { message: "[SAMPLE] Fix login page styling issues", author: "John Smith", date: "2023-05-18 10:15:45", sha: "e4f5g6h" },
118
+ { message: "[SAMPLE] Implement password reset functionality", author: "Alice Johnson", date: "2023-05-20 16:45:12", sha: "i7j8k9l" },
119
+ { message: "[SAMPLE] Add payment gateway integration", author: "Bob Brown", date: "2023-05-22 09:20:33", sha: "m2n3o4p" },
120
+ { message: "[SAMPLE] Update README with API documentation", author: "Charlie Davis", date: "2023-05-25 11:05:56", sha: "q5r6s7t" }
121
+ ]
122
+
123
+ # Generate sample questions
124
+ self.class.questions_per_round.times do |i|
125
+ # Select a random commit
126
+ commit = sample_commits[i % sample_commits.size]
127
+
128
+ # Select 4 random branch names
129
+ branch_options = sample_branches.sample(4)
130
+
131
+ # Choose a correct branch
132
+ correct_branch = branch_options.sample
133
+
134
+ questions << {
135
+ question: "Which branch was this commit originally made on?\n\n \"#{commit[:message]}\"",
136
+ commit_info: "#{commit[:sha]} (by #{commit[:author]} on #{commit[:date]})",
137
+ options: branch_options,
138
+ correct_answer: correct_branch
139
+ }
140
+ end
141
+
142
+ questions
143
+ end
144
+
145
+ def evaluate_answers(question, player_answers)
146
+ results = {}
147
+
148
+ player_answers.each do |player_name, answer_data|
149
+ answered = answer_data[:answered] || false
150
+ player_answer = answer_data[:answer]
151
+ time_taken = answer_data[:time_taken] || self.class.question_timeout
152
+
153
+ # Check if the answer is correct
154
+ correct = player_answer == question[:correct_answer]
155
+
156
+ # Calculate points
157
+ points = 0
158
+
159
+ # Base points for correct answer
160
+ if correct
161
+ points = 10
162
+
163
+ # Bonus points for fast answers
164
+ if time_taken < 5
165
+ points += 5 # Very fast (under 5 seconds)
166
+ elsif time_taken < 10
167
+ points += 3 # Pretty fast (under 10 seconds)
168
+ elsif time_taken < 12
169
+ points += 1 # Somewhat fast (under 12 seconds)
170
+ end
171
+ end
172
+
173
+ # Store the results
174
+ results[player_name] = {
175
+ answer: player_answer,
176
+ correct: correct,
177
+ points: points
178
+ }
179
+ end
180
+
181
+ results
182
+ end
183
+
184
+ private
185
+
186
+ def get_commits_for_branch branch
187
+ unique_commits = []
188
+
189
+ # Try different ways to reference the branch
190
+ begin
191
+ # Try a few different ways to reference the branch
192
+ got_commits = false
193
+
194
+ # First try as a local branch
195
+ cmd = "cd #{@repo.dir.path} && git log --pretty '#{branch}' --max-count=5 2>/dev/null"
196
+ commit_output = `#{cmd}`
197
+
198
+ # Process commits if we found any
199
+ commits = commit_output.split("commit ")[1..-1]
200
+
201
+ commits.each do |commit|
202
+
203
+ # Extract commit info
204
+ sha = commit.lines[0].split(" ")[0].strip
205
+ author = commit.lines[1].gsub("Author: ", "").split("<")[0].strip
206
+ date = commit.lines[2].gsub("Date: ", "").strip
207
+ message = commit.lines[4..-1].join("\n")
208
+
209
+ next unless message.length > 10
210
+ next if message.include?("Merge pull request")
211
+ # Store this commit info
212
+ unique_commits << {
213
+ sha: sha,
214
+ message: message,
215
+ author: author,
216
+ date: date
217
+ }
218
+ end
219
+
220
+ rescue => e
221
+ # If we hit any errors with this branch, just skip it
222
+ []
223
+ end
224
+
225
+ unique_commits
226
+ end
227
+ end
228
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_game_show
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-07 00:00:00.000000000 Z
11
+ date: 2025-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -213,6 +213,7 @@ files:
213
213
  - lib/git_game_show/updater.rb
214
214
  - lib/git_game_show/version.rb
215
215
  - mini_games/author_quiz.rb
216
+ - mini_games/branch_detective.rb
216
217
  - mini_games/commit_message_completion.rb
217
218
  - mini_games/date_ordering_quiz.rb
218
219
  - mini_games/file_quiz.rb