Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- The interactive `backup` command now backs up each name it is given, so `backup octocat github` backs up `octocat` and then `github`, as the command line does, instead of looking up the single name `octocat github` on GitHub and failing. A name that fails is reported and the others are still backed up; the command still counts as one backup run for usage reporting, and its usage hint reads `Usage: backup <user/org> [user/org2] ...`
- A scheduled daemon backup no longer stops partway when one user or organization fails with an unchecked exception (such as a `GHException` from github-api while listing repositories): the failure is logged as an error like any other, the remaining users and organizations are still backed up, and the run is still logged and reported as completed. Previously only an `IOException` was handled, so the rest of that run was skipped until the next interval
- A backup that reaches the GitHub rate limit no longer looks hung: the GitHub client has always waited silently for the limit to reset, for up to an hour, and now a notice on standard error says so first, with the expected reset time, and suggests `GITHUB_TOKEN` when running anonymously. The waiting itself is unchanged and is documented in `USER_GUIDE.md` and `COMMANDS.md`
- `GITHUB_TOKEN` is no longer dropped when the startup check fails for a reason unrelated to the token: only a `401` now prints `Invalid or expired GITHUB_TOKEN` and falls back to anonymous access, while any other failure, such as a network failure, a GitHub error or a `403` from `GET /user`, prints `Could not verify GITHUB_TOKEN` and keeps the token, so a brief outage at startup no longer leaves a daemon limited to 60 requests per hour until it is restarted
Expand Down
2 changes: 1 addition & 1 deletion COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Once in interactive mode, the following commands are available at the `>` prompt

| Command | Description |
|---------|-------------|
| `backup <user/org>` | Back up all public repositories for the given GitHub user or organization |
| `backup <user/org> [user/org2] ...` | Back up all public repositories for each GitHub user or organization given, one after another. Names are separated by spaces or tabs; one that fails is reported and the rest are still backed up |
| `status` | Display the backup directory path and a summary of all backed-up repositories |
| `help` | Show the list of available interactive commands |
| `exit` | Exit interactive mode and terminate the application |
Expand Down
2 changes: 1 addition & 1 deletion USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Available interactive commands:

| Command | Description |
|---------|-------------|
| `backup <user/org>` | Back up all public repositories for the specified user or organization |
| `backup <user/org> [user/org2] ...` | Back up all public repositories for each specified user or organization, as on the command line (for example, `backup octocat github`) |
| `status` | Show the backup directory, number of users/organizations, and a list of all backed up repositories |
| `help` | Show the list of available interactive commands |
| `exit` | Quit the interactive session |
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/github/backup/BackupCommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ private void runInteractiveMode() {
case "backup":
if (parts.length < 2) {
System.out.println("Error: Please specify a user or organization");
System.out.println("Usage: backup <user/org>");
System.out.println("Usage: backup <user/org> [user/org2] ...");
} else {
String userOrOrg = parts[1].trim();
try {
backupService.backupUserRepositories(userOrOrg);
} catch (Exception e) {
System.err.println("Error backing up " + userOrOrg + ": " + e.getMessage());
// Several names are backed up one after another, as on the command line
for (String userOrOrg : parts[1].trim().split("\\s+")) {
try {
backupService.backupUserRepositories(userOrOrg);
} catch (Exception e) {
System.err.println("Error backing up " + userOrOrg + ": " + e.getMessage());
}
}
usageReporting.backupCompleted();
}
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/com/github/backup/BackupCommandLineRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,41 @@ void testRun_InteractiveMode_BackupArgumentIsTrimmed() throws Exception {
verify(backupService).backupUserRepositories("octocat");
}

@Test
void testRun_InteractiveMode_BackupSeveralNames_EachBackedUpSeparately() throws Exception {
provideInput("backup octocat github\texit-user\nexit\n");

runner.run("-i");

verify(backupService).backupUserRepositories("octocat");
verify(backupService).backupUserRepositories("github");
verify(backupService).backupUserRepositories("exit-user");
verify(backupService, never()).backupUserRepositories("octocat github\texit-user");
// One command is one backup run, however many names it lists
verify(usageReporting, times(1)).backupCompleted();
}

@Test
void testRun_InteractiveMode_BackupSeveralNames_FailureDoesNotStopTheOthers() throws Exception {
doThrow(new IOException("Test exception"))
.when(backupService).backupUserRepositories("erroruser");
provideInput("backup erroruser gooduser\nexit\n");

runner.run("-i");

assertTrue(stderr().contains("Error backing up erroruser: Test exception"));
verify(backupService).backupUserRepositories("gooduser");
verify(usageReporting, times(1)).backupCompleted();
}

@Test
void testRun_InteractiveMode_BackupWithoutTarget() throws Exception {
provideInput("backup\nexit\n");

runner.run("-i");

assertTrue(stdout().contains("Error: Please specify a user or organization"));
assertTrue(stdout().contains("Usage: backup <user/org>"));
assertTrue(stdout().contains("Usage: backup <user/org> [user/org2] ..."));
verifyNoInteractions(backupService, usageReporting);
}

Expand Down
Loading