1
2
3
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Which Bitbucket workspace a command acts on.
//!
//! There is no api call left that discovers a user's workspaces —
//! `GET /workspaces`, `GET /user/permissions/workspaces` and
//! `GET /user/permissions/repositories` were all removed by Atlassian under
//! CHANGE-2770 and now return 410 — so this resolves entirely from local input.
use crateProject;
use crate;
use cratecredentials;
use crate;
use crateFormat;
use craterepo;
/// Splits a comma-separated `--workspace`/`BB_WORKSPACE` value into slugs:
/// trims whitespace, drops empty segments, and deduplicates while preserving
/// order.
/// The workspaces to act on, in precedence order:
///
/// 1. `--workspace` (comma-separated).
/// 2. `BB_WORKSPACE` (same syntax).
/// 3. The workspace of the git remote in the current checkout, tried rather
/// than required.
/// 4. None of the above: a config error naming both `--workspace` and
/// `BB_WORKSPACE`, rather than silently acting on nothing.
/// The single workspace to act on. Commands that operate on exactly one
/// workspace take the first slug of `resolve_list`, so `--workspace a,b` is a
/// harmless superset rather than a second syntax to learn.
///
/// No empty-list guard here: `resolve_list` only ever returns a non-empty
/// `Vec` or an `Err`, never `Ok(vec![])`, so there is nothing for one to
/// catch. Do not "restore" it.
/// The per-command context for workspace-scoped commands.
///
/// Deliberately a separate type from `Ctx` rather than `Ctx` with an
/// `Option<RepoSlug>`: a repository that does not exist yet has no slug, and
/// every existing consumer of `Ctx` would otherwise have to handle a `None`
/// that cannot occur for it.
/// Every project in the workspace the token can see.
///
/// One fetch serves both `bb project list` and `bb repo create`'s picker, so
/// the endpoint is written and tested once.
pub async