Skip to content

Commit 845ec2c

Browse files
committed
feat(mob): add functionality to include non-team members in the mob session
1 parent 48aa07b commit 845ec2c

File tree

5 files changed

+107
-15
lines changed

5 files changed

+107
-15
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,19 @@ $ cargo install git-mob-tool
9494
Co-authored-by: Emi Martinez <[email protected]>
9595
```
9696

97+
- To add a non-team member to the mob session:
98+
99+
```console
100+
$ git mob --add "Diego Maradona" [email protected]
101+
```
102+
97103
- To clear the mob session:
98104

99105
```console
100106
$ git mob --clear
101107
```
102108

103-
- To view the co-authors in the current mob session:
109+
- To view the co-authors in the mob session:
104110

105111
```console
106112
$ git mob --list

src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ mod tests {
9191
clear: true,
9292
list: false,
9393
trailers: false,
94+
add: None,
9495
},
9596
};
9697

@@ -126,6 +127,7 @@ mod tests {
126127
clear: false,
127128
list: false,
128129
trailers: false,
130+
add: None,
129131
},
130132
};
131133

src/commands/mob.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ use std::{error::Error, io::Write};
66
#[derive(Parser)]
77
#[command(arg_required_else_help = true)]
88
pub(crate) struct Mob {
9-
/// Sets active co-author(s) for pair/mob programming session
9+
/// Sets co-author(s) from team member(s) in the mob/pair programming session
10+
///
11+
/// This will clear any existing co-author(s) in current session
1012
///
1113
/// Usage example: git mob pair --with lm mj
1214
#[arg(short='w', long="with", num_args=0.., value_name="COAUTHOR_KEY")]
1315
pub(crate) with: Option<Vec<String>>,
14-
/// Clears mob/pair programming session. Going solo!
16+
/// Adds co-author to the mob/pair programming session (usually non-team member)
17+
///
18+
/// Usage example: git mob --add "Leo Messi" [email protected]
19+
#[arg(short = 'a', long = "add", num_args=2, value_names=["COAUTHOR_NAME", "COAUTHOR_EMAIL"])]
20+
pub(crate) add: Option<Vec<String>>,
21+
/// Clears the mob/pair programming session. Going solo!
1522
///
1623
/// Usage example: git mob --clear
1724
#[arg(short = 'c', long = "clear")]
1825
pub(crate) clear: bool,
19-
/// Lists co-author(s) in current mob/pair programming session
26+
/// Lists co-author(s) in the mob/pair programming session
2027
///
2128
/// Usage example: git mob --list
2229
#[arg(short = 'l', long = "list")]
2330
pub(crate) list: bool,
24-
/// Lists Co-authored-by trailers in current mob/pair programming session
31+
/// Lists Co-authored-by trailers in the mob/pair programming session
2532
///
2633
/// Usage example: git mob --trailers
2734
#[arg(short = 't', long = "trailers")]
@@ -99,6 +106,12 @@ impl Mob {
99106
}
100107
}
101108

109+
if let Some([name, email]) = self.add.as_deref() {
110+
let coauthor = format!("{name} <{email}>");
111+
coauthor_repo.add_to_mob(&coauthor)?;
112+
writeln!(out, "{coauthor}")?
113+
}
114+
102115
Ok(())
103116
}
104117
}
@@ -124,6 +137,7 @@ mod tests {
124137
with: None,
125138
list: false,
126139
trailers: false,
140+
add: None,
127141
};
128142

129143
let mut out = Vec::new();
@@ -152,6 +166,7 @@ mod tests {
152166
clear: false,
153167
with: None,
154168
trailers: false,
169+
add: None,
155170
};
156171

157172
let mut out = Vec::new();
@@ -175,6 +190,7 @@ mod tests {
175190
clear: false,
176191
with: None,
177192
trailers: false,
193+
add: None,
178194
};
179195

180196
let mut out = Vec::new();
@@ -203,6 +219,7 @@ mod tests {
203219
clear: false,
204220
with: None,
205221
trailers: true,
222+
add: None,
206223
};
207224

208225
let mut out = Vec::new();
@@ -230,6 +247,7 @@ mod tests {
230247
clear: false,
231248
with: None,
232249
trailers: true,
250+
add: None,
233251
};
234252

235253
let mut out = Vec::new();
@@ -256,6 +274,7 @@ mod tests {
256274
clear: false,
257275
list: false,
258276
trailers: false,
277+
add: None,
259278
};
260279

261280
let mut out = Vec::new();
@@ -306,6 +325,7 @@ mod tests {
306325
clear: false,
307326
list: false,
308327
trailers: false,
328+
add: None,
309329
};
310330

311331
let mut out = Vec::new();
@@ -336,6 +356,7 @@ mod tests {
336356
clear: false,
337357
list: false,
338358
trailers: false,
359+
add: None,
339360
};
340361

341362
let mut out = Vec::new();
@@ -346,4 +367,32 @@ mod tests {
346367

347368
Ok(())
348369
}
370+
371+
#[test]
372+
fn test_add_to_mob() -> Result<(), Box<dyn std::error::Error>> {
373+
let name = "Leo Messi";
374+
let email = "[email protected]";
375+
376+
let mut mock_coauthor_repo = MockCoauthorRepo::new();
377+
mock_coauthor_repo
378+
.expect_add_to_mob()
379+
.with(predicate::eq(format!("{name} <{email}>")))
380+
.once()
381+
.returning(|_| Ok(()));
382+
383+
let mob_cmd = Mob {
384+
add: Some(vec![name.to_owned(), email.to_owned()]),
385+
with: None,
386+
clear: false,
387+
list: false,
388+
trailers: false,
389+
};
390+
391+
let mut out = Vec::new();
392+
mob_cmd.handle(&mock_coauthor_repo, &mut out)?;
393+
394+
assert_eq!(out, format!("{name} <{email}>\n").as_bytes());
395+
396+
Ok(())
397+
}
349398
}

tests/help.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,29 @@ Commands:
3535
3636
Options:
3737
-w, --with [<COAUTHOR_KEY>...]
38-
Sets active co-author(s) for pair/mob programming session
38+
Sets co-author(s) from team member(s) in the mob/pair programming session
39+
40+
This will clear any existing co-author(s) in current session
3941
4042
Usage example: git mob pair --with lm mj
4143
44+
-a, --add <COAUTHOR_NAME> <COAUTHOR_EMAIL>
45+
Adds co-author to the mob/pair programming session (usually non-team member)
46+
47+
Usage example: git mob --add "Leo Messi" [email protected]
48+
4249
-c, --clear
43-
Clears mob/pair programming session. Going solo!
50+
Clears the mob/pair programming session. Going solo!
4451
4552
Usage example: git mob --clear
4653
4754
-l, --list
48-
Lists co-author(s) in current mob/pair programming session
55+
Lists co-author(s) in the mob/pair programming session
4956
5057
Usage example: git mob --list
5158
5259
-t, --trailers
53-
Lists Co-authored-by trailers in current mob/pair programming session
60+
Lists Co-authored-by trailers in the mob/pair programming session
5461
5562
Usage example: git mob --trailers
5663
@@ -83,12 +90,20 @@ Commands:
8390
help Print this message or the help of the given subcommand(s)
8491
8592
Options:
86-
-w, --with [<COAUTHOR_KEY>...] Sets active co-author(s) for pair/mob programming session
87-
-c, --clear Clears mob/pair programming session. Going solo!
88-
-l, --list Lists co-author(s) in current mob/pair programming session
89-
-t, --trailers Lists Co-authored-by trailers in current mob/pair programming session
90-
-h, --help Print help (see more with '--help')
91-
-V, --version Print version
93+
-w, --with [<COAUTHOR_KEY>...]
94+
Sets co-author(s) from team member(s) in the mob/pair programming session
95+
-a, --add <COAUTHOR_NAME> <COAUTHOR_EMAIL>
96+
Adds co-author to the mob/pair programming session (usually non-team member)
97+
-c, --clear
98+
Clears the mob/pair programming session. Going solo!
99+
-l, --list
100+
Lists co-author(s) in the mob/pair programming session
101+
-t, --trailers
102+
Lists Co-authored-by trailers in the mob/pair programming session
103+
-h, --help
104+
Print help (see more with '--help')
105+
-V, --version
106+
Print version
92107
"#
93108
));
94109

tests/mob.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ fn test_mob_with_multiselect_when_press_escape(ctx: TestContextCli) -> Result<()
180180
Ok(())
181181
}
182182

183+
#[test_context(TestContextCli, skip_teardown)]
184+
#[test]
185+
fn test_add_to_mob(ctx: TestContextCli) -> Result<(), Box<dyn Error>> {
186+
// adding a team member
187+
ctx.git()
188+
.args(["mob", "--add", "Leo Messi", "[email protected]"])
189+
.assert()
190+
.success()
191+
.stdout(predicate::str::diff("Leo Messi <[email protected]>\n"));
192+
193+
// mob list shows the added team member
194+
ctx.git()
195+
.args(["mob", "--list"])
196+
.assert()
197+
.success()
198+
.stdout(predicate::str::diff("Leo Messi <[email protected]>\n"));
199+
200+
Ok(())
201+
}
202+
183203
#[test_context(TestContextCli, skip_teardown)]
184204
#[test]
185205
fn test_clear_mob(ctx: TestContextCli) -> Result<(), Box<dyn Error>> {

0 commit comments

Comments
 (0)