Skip to content

Commit aacf0f2

Browse files
authored
Merge pull request #128 from rust-lang/remove-ability-to-sync-github-apps
remove ability to sync GitHub apps
2 parents 9e20690 + fb434cb commit aacf0f2

File tree

7 files changed

+4
-370
lines changed

7 files changed

+4
-370
lines changed

sync-team/src/github/api/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,9 @@ impl fmt::Display for RepoPermission {
261261
}
262262
}
263263

264-
#[derive(serde::Deserialize, Debug)]
265-
pub(crate) struct OrgAppInstallation {
266-
#[serde(rename = "id")]
267-
pub(crate) installation_id: u64,
268-
pub(crate) app_id: u64,
269-
}
270-
271-
#[derive(serde::Deserialize, Debug)]
272-
pub(crate) struct RepoAppInstallation {
273-
pub(crate) name: String,
274-
}
275-
276264
#[derive(serde::Deserialize, Debug, Clone)]
277265
pub(crate) struct Repo {
278266
pub(crate) node_id: String,
279-
#[serde(rename = "id")]
280-
pub(crate) repo_id: u64,
281267
pub(crate) name: String,
282268
#[serde(alias = "owner", deserialize_with = "repo_owner")]
283269
pub(crate) org: String,

sync-team/src/github/api/read.rs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::github::api::{
2-
BranchProtection, GraphNode, GraphNodes, GraphPageInfo, HttpClient, Login, OrgAppInstallation,
3-
Repo, RepoAppInstallation, RepoTeam, RepoUser, Team, TeamMember, TeamRole, team_node_id,
4-
url::GitHubUrl, user_node_id,
2+
BranchProtection, GraphNode, GraphNodes, GraphPageInfo, HttpClient, Login, Repo, RepoTeam,
3+
RepoUser, Team, TeamMember, TeamRole, team_node_id, url::GitHubUrl, user_node_id,
54
};
6-
use anyhow::Context;
75
use reqwest::Method;
86
use std::collections::{HashMap, HashSet};
97

@@ -14,16 +12,6 @@ pub(crate) trait GithubRead {
1412
/// Get the owners of an org
1513
fn org_owners(&self, org: &str) -> anyhow::Result<HashSet<u64>>;
1614

17-
/// Get the app installations of an org
18-
fn org_app_installations(&self, org: &str) -> anyhow::Result<Vec<OrgAppInstallation>>;
19-
20-
/// Get the repositories enabled for an app installation.
21-
fn app_installation_repos(
22-
&self,
23-
installation_id: u64,
24-
org: &str,
25-
) -> anyhow::Result<Vec<RepoAppInstallation>>;
26-
2715
/// Get all teams associated with a org
2816
///
2917
/// Returns a list of tuples of team name and slug
@@ -124,56 +112,6 @@ impl GithubRead for GitHubApiRead {
124112
Ok(owners)
125113
}
126114

127-
fn org_app_installations(&self, org: &str) -> anyhow::Result<Vec<OrgAppInstallation>> {
128-
#[derive(serde::Deserialize, Debug)]
129-
struct InstallationPage {
130-
installations: Vec<OrgAppInstallation>,
131-
}
132-
133-
let mut installations = Vec::new();
134-
self.client.rest_paginated(
135-
&Method::GET,
136-
&GitHubUrl::orgs(org, "installations")?,
137-
|response: InstallationPage| {
138-
installations.extend(response.installations);
139-
Ok(())
140-
},
141-
)?;
142-
Ok(installations)
143-
}
144-
145-
fn app_installation_repos(
146-
&self,
147-
installation_id: u64,
148-
org: &str,
149-
) -> anyhow::Result<Vec<RepoAppInstallation>> {
150-
#[derive(serde::Deserialize, Debug)]
151-
struct InstallationPage {
152-
repositories: Vec<RepoAppInstallation>,
153-
}
154-
155-
let mut installations = Vec::new();
156-
let url = if self.client.github_tokens.is_pat() {
157-
// we are using a PAT
158-
format!("user/installations/{installation_id}/repositories")
159-
} else {
160-
// we are using a GitHub App
161-
"installation/repositories".to_string()
162-
};
163-
164-
self.client
165-
.rest_paginated(
166-
&Method::GET,
167-
&GitHubUrl::new(&url, org),
168-
|response: InstallationPage| {
169-
installations.extend(response.repositories);
170-
Ok(())
171-
},
172-
)
173-
.with_context(|| format!("failed to send rest paginated request to {url}"))?;
174-
Ok(installations)
175-
}
176-
177115
fn org_teams(&self, org: &str) -> anyhow::Result<Vec<(String, String)>> {
178116
let mut teams = Vec::new();
179117

@@ -308,7 +246,6 @@ impl GithubRead for GitHubApiRead {
308246
query($owner: String!, $name: String!) {
309247
repository(owner: $owner, name: $name) {
310248
id
311-
databaseId
312249
autoMergeAllowed
313250
description
314251
homepageUrl
@@ -328,7 +265,6 @@ impl GithubRead for GitHubApiRead {
328265
// Equivalent of `node_id` of the Rest API
329266
id: String,
330267
// Equivalent of `id` of the Rest API
331-
database_id: u64,
332268
auto_merge_allowed: Option<bool>,
333269
description: Option<String>,
334270
homepage_url: Option<String>,
@@ -345,7 +281,6 @@ impl GithubRead for GitHubApiRead {
345281
)?;
346282

347283
let repo = result.repository.map(|repo_response| Repo {
348-
repo_id: repo_response.database_id,
349284
node_id: repo_response.id,
350285
name: repo.to_string(),
351286
description: repo_response.description.unwrap_or_default(),

sync-team/src/github/api/tokens.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ impl GitHubTokens {
4646
GitHubTokens::Pat(pat) => Ok(pat),
4747
}
4848
}
49-
50-
pub fn is_pat(&self) -> bool {
51-
matches!(self, GitHubTokens::Pat(_))
52-
}
5349
}
5450

5551
fn org_name_from_env_var(env_var: &str) -> Option<String> {

sync-team/src/github/api/write.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ impl GitHubWrite {
237237
if self.dry_run {
238238
Ok(Repo {
239239
node_id: String::from("ID"),
240-
repo_id: 0,
241240
name: name.to_string(),
242241
org: org.to_string(),
243242
description: settings.description.clone(),
@@ -280,54 +279,6 @@ impl GitHubWrite {
280279
Ok(())
281280
}
282281

283-
pub(crate) fn add_repo_to_app_installation(
284-
&self,
285-
installation_id: u64,
286-
repository_id: u64,
287-
org: &str,
288-
) -> anyhow::Result<()> {
289-
debug!("Adding repository {repository_id} to installation {installation_id}");
290-
if !self.dry_run {
291-
self.client
292-
.req(
293-
Method::PUT,
294-
&GitHubUrl::new(
295-
&format!(
296-
"user/installations/{installation_id}/repositories/{repository_id}"
297-
),
298-
org,
299-
),
300-
)?
301-
.send()?
302-
.custom_error_for_status()?;
303-
}
304-
Ok(())
305-
}
306-
307-
pub(crate) fn remove_repo_from_app_installation(
308-
&self,
309-
installation_id: u64,
310-
repository_id: u64,
311-
org: &str,
312-
) -> anyhow::Result<()> {
313-
debug!("Removing repository {repository_id} from installation {installation_id}");
314-
if !self.dry_run {
315-
self.client
316-
.req(
317-
Method::DELETE,
318-
&GitHubUrl::new(
319-
&format!(
320-
"user/installations/{installation_id}/repositories/{repository_id}"
321-
),
322-
org,
323-
),
324-
)?
325-
.send()?
326-
.custom_error_for_status()?;
327-
}
328-
Ok(())
329-
}
330-
331282
/// Update a team's permissions to a repo
332283
pub(crate) fn update_team_repo_permissions(
333284
&self,

0 commit comments

Comments
 (0)