Skip to content

Added CLI command to automate team and repo archival#2420

Open
Sandijigs wants to merge 1 commit intorust-lang:mainfrom
Sandijigs:add/archive-command
Open

Added CLI command to automate team and repo archival#2420
Sandijigs wants to merge 1 commit intorust-lang:mainfrom
Sandijigs:add/archive-command

Conversation

@Sandijigs
Copy link
Copy Markdown
Contributor

This PR adds a new archive subcommand to the CLI that handles moving TOML files to the archive/ directory, clearing team access on repos, and moving team members to alumni .
Example usage:

  • cargo run -- archive repo rust-lang/homu

  • cargo run -- archive team project-generic-associated-types

For repos, it moves the file to repos/archive/{org}/ and clears all entries under [access.teams].
For teams, it moves the file to teams/archive/, sets leads and members to empty, and moves everyone into alumni.

I used toml_edit to modify the TOML files so that only the parts that need to change are touched everything else (comments, formatting, ordering) stays the same.

Closes #1547

@rustbot

This comment has been minimized.

@Sandijigs Sandijigs force-pushed the add/archive-command branch from f71bf56 to 9335836 Compare April 15, 2026 20:49
@rustbot

This comment has been minimized.

@Sandijigs Sandijigs force-pushed the add/archive-command branch from 9335836 to dfedaf1 Compare April 15, 2026 21:11
@github-actions
Copy link
Copy Markdown

Dry-run check results

[WARN  rust_team::sync] sync-team is running in dry mode, no changes will be applied.
[INFO  rust_team::sync] synchronizing crates-io
[INFO  rust_team::sync] synchronizing github

@marcoieni
Copy link
Copy Markdown
Member

I tested archiving a team, but alumni are in one line. Can we put one member per line?
image

@Sandijigs Sandijigs force-pushed the add/archive-command branch from dfedaf1 to f595a4d Compare April 15, 2026 21:40
@Sandijigs
Copy link
Copy Markdown
Contributor Author

The alumni are now listed one per line.

Screenshot 2026-04-15 at 10 37 38 pm

@marcoieni
Copy link
Copy Markdown
Member

marcoieni commented Apr 15, 2026

One thing I noticed: when archiving a team, you should remove the team access from other repos, like it was done in #2214
Probably this is more complicated, so no need to do this if you don't have time.

EDIT: actually you already have the logic to remove teams from a repo so maybe it's not that difficult!

@Sandijigs Sandijigs force-pushed the add/archive-command branch from f595a4d to dcb2e59 Compare April 16, 2026 20:47
@Sandijigs
Copy link
Copy Markdown
Contributor Author

I added a remove_team_from_repos function that runs after the team file is archived. It scans all repo TOML files and removes the archived team's entry from any [access.teams] block where it appears.

Comment thread Cargo.toml
tempfile = "3.19.1"
thiserror = "2.0.18"
toml = "1.0"
toml_edit = "0.22"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the latest version of this package? I.e. what cargo add adds.

Comment thread src/main.rs
remove_team_from_repos(data_dir, name)?;

Ok(())
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is very long. I would extract it into smaller ones.

Comment thread src/main.rs
Comment on lines +708 to +712
std::fs::create_dir_all(&dest_dir)
.with_context(|| format!("failed to create directory {}", dest_dir.display()))?;
std::fs::write(&dest, doc.to_string())
.with_context(|| format!("failed to write {}", dest.display()))?;
std::fs::remove_file(&src).with_context(|| format!("failed to remove {}", src.display()))?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is duplicated among the two functions. So it would be nice to extract it into a function and reuse it.

In general, please inspect your code and find opportunities similar to this one to extract common code.

Comment thread src/main.rs Outdated
Comment on lines +701 to +706
if let Some(access) = doc.get_mut("access")
&& let Some(teams) = access.get_mut("teams")
&& let Some(table) = teams.as_table_mut()
{
table.clear();
}
Copy link
Copy Markdown
Member

@marcoieni marcoieni Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is also duplicated with the other function. It would be nice to extract it

@Sandijigs Sandijigs force-pushed the add/archive-command branch from dcb2e59 to ce7b140 Compare April 17, 2026 12:38
@Sandijigs
Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out. I have extracted the [access.teams] navigation into a shared get_access_teams helper and updated both archive_repo and remove_team_from_repos to use it.

Copy link
Copy Markdown
Contributor

@ubiratansoares ubiratansoares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sandijigs Added some comments

Comment thread src/main.rs Outdated
Comment on lines +740 to +741
let mut all_alumni: Vec<String> = Vec::new();
let mut seen = HashSet::new();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use only the hashset here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out , Should I switch IndexSet from indexmap? since it handles both deduplication and preserves insertion order in a single data structure. which was what I was going for when i used hashset

Comment thread src/main.rs Outdated
Comment on lines +764 to +765
people_table.insert("leads", toml_edit::value(toml_edit::Array::new()));
people_table.insert("members", toml_edit::value(toml_edit::Array::new()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that

 toml_edit::Array::new().into()

works equality as

toml_edit::value(toml_edit::Array::new())

but it reads a bit shorter (also better, imho)

Comment thread src/main.rs
@rustbot

This comment has been minimized.

@jieyouxu jieyouxu added needs-infra-admin-review This change requires one of the `infra-admins` to review. S-waiting-on-review Status: waiting on review from a team/WG/PG lead, an infra-admin, and/or a team-repo-admin. labels Apr 22, 2026
@Sandijigs Sandijigs force-pushed the add/archive-command branch from ce7b140 to 323852a Compare April 22, 2026 11:32
@Sandijigs Sandijigs force-pushed the add/archive-command branch from 323852a to fb54a10 Compare April 22, 2026 14:14
@rustbot
Copy link
Copy Markdown

rustbot commented Apr 22, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Sandijigs
Copy link
Copy Markdown
Contributor Author

I've switched to IndexSet instead of the HashSet combo , It is definately more cleaner. Also swapped toml_edit::value() for .into() like @ubiratansoares suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-infra-admin-review This change requires one of the `infra-admins` to review. S-waiting-on-review Status: waiting on review from a team/WG/PG lead, an infra-admin, and/or a team-repo-admin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a command for archiving teams and repos

5 participants