Skip to content

Commit 5430675

Browse files
authored
Remove the add-repo command and its associated code (#1452)
1 parent 40069c8 commit 5430675

File tree

2 files changed

+0
-238
lines changed

2 files changed

+0
-238
lines changed

src/github.rs

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -185,152 +185,8 @@ impl GitHubApi {
185185
}
186186
Ok(result)
187187
}
188-
189-
pub(crate) fn repo(&self, org: &str, repo: &str) -> Result<Option<Repo>, Error> {
190-
let resp = self
191-
.prepare(true, Method::GET, &format!("repos/{}/{}", org, repo))?
192-
.send()?;
193-
match resp.status() {
194-
reqwest::StatusCode::OK => Ok(Some(resp.json()?)),
195-
reqwest::StatusCode::NOT_FOUND => Ok(None),
196-
_ => Err(resp.error_for_status().unwrap_err().into()),
197-
}
198-
}
199-
200-
pub(crate) fn repo_teams(&self, org: &str, repo: &str) -> Result<Vec<Team>, Error> {
201-
let resp = self
202-
.prepare(true, Method::GET, &format!("repos/{}/{}/teams", org, repo))?
203-
.send()?;
204-
Ok(resp.error_for_status()?.json()?)
205-
}
206-
207-
pub(crate) fn repo_collaborators(
208-
&self,
209-
org: &str,
210-
repo: &str,
211-
) -> Result<Vec<RepoCollaborator>, Error> {
212-
let resp = self
213-
.prepare(
214-
true,
215-
Method::GET,
216-
&format!("repos/{org}/{repo}/collaborators?affiliation=direct"),
217-
)?
218-
.send()?;
219-
220-
Ok(resp.error_for_status()?.json()?)
221-
}
222-
223-
pub(crate) fn protected_branches(&self, org: &str, repo: &str) -> Result<Vec<Branch>, Error> {
224-
let resp = self
225-
.prepare(
226-
true,
227-
Method::GET,
228-
&format!("repos/{}/{}/branches?protected=true", org, repo),
229-
)?
230-
.send()?;
231-
Ok(resp.error_for_status()?.json()?)
232-
}
233-
234-
pub(crate) fn branch_protection(
235-
&self,
236-
org: &str,
237-
repo: &str,
238-
branch: &str,
239-
) -> Result<BranchProtection, Error> {
240-
let resp = self
241-
.prepare(
242-
true,
243-
Method::GET,
244-
&format!("repos/{}/{}/branches/{}/protection", org, repo, branch),
245-
)?
246-
.send()?;
247-
Ok(resp.error_for_status()?.json()?)
248-
}
249188
}
250189

251190
fn user_node_id(id: u64) -> String {
252191
base64::encode(format!("04:User{id}"))
253192
}
254-
255-
#[derive(serde::Deserialize, Debug)]
256-
pub(crate) struct Repo {
257-
pub(crate) description: Option<String>,
258-
pub(crate) homepage: Option<String>,
259-
}
260-
261-
#[derive(serde::Deserialize, Debug)]
262-
pub(crate) struct Team {
263-
pub(crate) name: String,
264-
pub(crate) permission: Permission,
265-
}
266-
267-
#[derive(serde::Deserialize, Debug)]
268-
pub(crate) struct Permission(String);
269-
270-
impl Permission {
271-
pub(crate) fn as_toml(&self) -> &str {
272-
match self.0.as_str() {
273-
"push" => "write",
274-
s => s,
275-
}
276-
}
277-
}
278-
279-
#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
280-
#[serde(rename_all = "snake_case")]
281-
pub(crate) enum TeamPrivacy {
282-
Closed,
283-
Secret,
284-
}
285-
286-
#[derive(serde::Deserialize, Debug)]
287-
pub(crate) struct Branch {
288-
pub(crate) name: String,
289-
}
290-
291-
#[derive(serde::Deserialize, Debug)]
292-
pub(crate) struct BranchProtection {
293-
pub(crate) required_status_checks: Option<StatusChecks>,
294-
pub(crate) required_pull_request_reviews: Option<RequiredReviews>,
295-
}
296-
297-
#[derive(serde::Deserialize, Debug)]
298-
pub(crate) struct StatusChecks {
299-
pub(crate) contexts: Vec<String>,
300-
}
301-
302-
#[derive(serde::Deserialize, Debug)]
303-
pub(crate) struct RequiredReviews {
304-
pub(crate) dismiss_stale_reviews: bool,
305-
}
306-
307-
#[derive(serde::Deserialize, Debug)]
308-
pub(crate) struct RepoCollaborator {
309-
#[serde(alias = "login")]
310-
pub(crate) name: String,
311-
pub(crate) permissions: Permissions,
312-
}
313-
314-
#[derive(serde::Deserialize, Debug)]
315-
pub(crate) struct Permissions {
316-
triage: bool,
317-
push: bool,
318-
maintain: bool,
319-
admin: bool,
320-
}
321-
322-
impl Permissions {
323-
pub(crate) fn highest(&self) -> &str {
324-
if self.admin {
325-
"admin"
326-
} else if self.maintain {
327-
"maintain"
328-
} else if self.push {
329-
"write"
330-
} else if self.triage {
331-
"triage"
332-
} else {
333-
"read"
334-
}
335-
}
336-
}

src/main.rs

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ enum Cli {
6161
help = "add a new person from their GitHub profile"
6262
)]
6363
AddPerson { github_name: String },
64-
#[structopt(
65-
name = "add-repo",
66-
help = "add a new repo config from an existing GitHub repo"
67-
)]
68-
AddRepo { org: String, name: String },
6964
#[structopt(name = "static-api", help = "generate the static API")]
7065
StaticApi { dest: String },
7166
#[structopt(name = "show-person", help = "print information about a person")]
@@ -188,95 +183,6 @@ fn run() -> Result<(), Error> {
188183

189184
info!("written data to {}", file);
190185
}
191-
Cli::AddRepo { org, name } => {
192-
#[derive(serde::Serialize, Debug)]
193-
#[serde(rename_all = "kebab-case")]
194-
struct AccessToAdd {
195-
#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
196-
teams: HashMap<String, String>,
197-
#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]
198-
individuals: HashMap<String, String>,
199-
}
200-
#[derive(serde::Serialize, Debug)]
201-
#[serde(rename_all = "kebab-case")]
202-
struct BranchToAdd {
203-
name: String,
204-
#[serde(skip_serializing_if = "Option::is_none")]
205-
dismiss_stale_review: Option<bool>,
206-
#[serde(skip_serializing_if = "Option::is_none")]
207-
ci_checks: Option<Vec<String>>,
208-
}
209-
#[derive(serde::Serialize, Debug)]
210-
#[serde(rename_all = "kebab-case")]
211-
struct RepoToAdd<'a> {
212-
org: &'a str,
213-
name: &'a str,
214-
description: &'a str,
215-
homepage: &'a Option<String>,
216-
bots: Vec<String>,
217-
access: AccessToAdd,
218-
#[serde(skip_serializing_if = "Vec::is_empty")]
219-
branch: Vec<BranchToAdd>,
220-
}
221-
let github = github::GitHubApi::new();
222-
let repo = match github.repo(&org, &name)? {
223-
Some(r) => r,
224-
None => bail!("The repo '{}/{}' was not found on GitHub", org, name),
225-
};
226-
let mut teams = HashMap::new();
227-
let mut bots = Vec::new();
228-
229-
const BOTS: &[&str] = &["bors", "rust-highfive", "rust-timer", "rustbot", "rfcbot"];
230-
let switch = |bot| {
231-
if bot == "rust-highfive" {
232-
"highfive".to_owned()
233-
} else {
234-
bot
235-
}
236-
};
237-
for team in github.repo_teams(&org, &name)? {
238-
if BOTS.contains(&team.name.as_str()) {
239-
let name = switch(team.name);
240-
bots.push(name.to_owned());
241-
} else if team.name == "bots" {
242-
bots.extend(BOTS.iter().map(|&s| switch(s.to_owned())));
243-
} else {
244-
teams.insert(team.name, team.permission.as_toml().to_owned());
245-
}
246-
}
247-
248-
let individuals = github
249-
.repo_collaborators(&org, &name)?
250-
.into_iter()
251-
.map(|c| (c.name, c.permissions.highest().to_owned()))
252-
.collect();
253-
254-
let mut branches = Vec::new();
255-
for branch in github.protected_branches(&org, &name)? {
256-
let protection = github.branch_protection(&org, &name, &branch.name)?;
257-
branches.push(BranchToAdd {
258-
name: branch.name,
259-
ci_checks: protection.required_status_checks.map(|c| c.contexts),
260-
dismiss_stale_review: protection
261-
.required_pull_request_reviews
262-
.map(|r| r.dismiss_stale_reviews),
263-
});
264-
}
265-
266-
let repo = RepoToAdd {
267-
org: &org,
268-
name: &name,
269-
description: &repo.description.unwrap_or_else(|| {
270-
format!("The {name} repo maintained by the rust-lang project")
271-
}),
272-
homepage: &repo.homepage,
273-
bots,
274-
access: AccessToAdd { teams, individuals },
275-
branch: branches,
276-
};
277-
let file = format!("repos/{org}/{name}.toml");
278-
std::fs::write(file, toml::to_string_pretty(&repo)?.as_bytes())?;
279-
}
280186
Cli::StaticApi { ref dest } => {
281187
let dest = PathBuf::from(dest);
282188
let generator = crate::static_api::Generator::new(&dest, &data)?;

0 commit comments

Comments
 (0)