Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
00ed45b
feat: added support to delete codespaces
AnishDe12020 Jul 26, 2022
6197f45
update: bump version
adrianmg Jul 29, 2022
21b41b8
fix(codespace): make user re-auth if unable to fetch codespaces
AnishDe12020 Jul 30, 2022
55803a0
refactor: use commander.js
AnishDe12020 Jul 30, 2022
bcfce4a
refactor: remove commander.js
AnishDe12020 Aug 1, 2022
a8eae41
test: added codespace scope to tests
AnishDe12020 Aug 1, 2022
587bb88
docs: update readme to show usage of codespaces command and update fi…
AnishDe12020 Aug 1, 2022
8ed64c2
docs(readme): fix indentation in file tree
AnishDe12020 Aug 3, 2022
5acd3ec
fix: print help if unknown command is passed
AnishDe12020 Aug 4, 2022
865b2b7
Merge branch 'feat/delete-codespaces' of github.com:AnishDe12020/gith…
AnishDe12020 Aug 4, 2022
51ecf43
refactor: use a utility function for repo/codespace label
AnishDe12020 Aug 4, 2022
10b0adf
update: add anish to README
adrianmg Sep 6, 2022
5f582ae
fix: stop printing help message if no repos selected
AnishDe12020 Sep 6, 2022
a0e7a7d
update: refactor arrow function for consistency
adrianmg Sep 6, 2022
ec7014f
update: more descriptive name for labels func
adrianmg Sep 6, 2022
1397859
update: package description
adrianmg Sep 6, 2022
602026f
improve: help command formatting
adrianmg Sep 6, 2022
31de3a6
update: README with more todos
adrianmg Sep 6, 2022
36ef81e
Merge branch 'feat/delete-codespaces' of github.com:AnishDe12020/gith…
adrianmg Sep 6, 2022
efc1a51
fix: missing string
adrianmg Sep 30, 2022
a5e8cda
fix: correct print message on canceling deletion of codespaces
adrianmg Sep 30, 2022
bbb23fd
update: const variables from package
adrianmg Sep 30, 2022
6397aae
update: make help command the default one
adrianmg Sep 30, 2022
79647eb
Bump clipboardy from 2.3.0 to 3.0.0
dependabot[bot] Sep 15, 2022
e794311
update: package description
adrianmg Sep 30, 2022
0f129b0
Bump ora from 5.4.1 to 6.1.2
dependabot[bot] Sep 15, 2022
d271fa9
Migration from CommonJS to ES Modules
adrianmg Sep 30, 2022
e341924
update: test to ES Modules
adrianmg Sep 30, 2022
12aac3a
Bump mocha from 9.2.2 to 10.0.0
adrianmg Sep 30, 2022
7d7bb93
Bump @octokit/auth-oauth-device from 3.1.2 to 4.0.2
adrianmg Sep 30, 2022
5db9794
add: hint how to select
adrianmg Sep 30, 2022
10cffb0
update: less obvious hint to select with space?
adrianmg Sep 30, 2022
9ef7d97
add: backup commands alias for repos
adrianmg Sep 30, 2022
809d683
update: document available commands
adrianmg Oct 1, 2022
f90b2c5
fix: importing assert
adrianmg Oct 1, 2022
5750a92
fix: tests workflow bump version 16
adrianmg Oct 1, 2022
02c9b8e
update: workflow can be dispatched manually
adrianmg Oct 1, 2022
840dd63
fix: add back npm install
adrianmg Oct 1, 2022
9822d5b
update: minor refactor
adrianmg Oct 1, 2022
f6c7e92
update: permissions for release drafter action
adrianmg Oct 1, 2022
1aaf5b3
test if this fixes it
adrianmg Oct 1, 2022
b3f530e
fix
adrianmg Oct 1, 2022
3f09c5d
remove: release draft is not needed anymore. BYE
adrianmg Oct 1, 2022
4058d55
merge: pr #39
jdvr Sep 29, 2022
44b7954
update: directory is recursive and takes unix into account
adrianmg Oct 2, 2022
35e46fe
update: homedir() directly imported from 'os'
adrianmg Oct 2, 2022
45a252d
update: package description since now you can do more than repos!
adrianmg Oct 2, 2022
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
31 changes: 0 additions & 31 deletions .github/release-drafter.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/release-drafter.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Tests
on: pull_request
on: [pull_request, workflow_dispatch]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '10.x'
node-version: 16
- run: npm install
- run: npm test
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,29 @@
</p>

## Installation and Usage

To install the latest version of github-pewpew CLI, run this command:

```
npm i -g github-pewpew
```

To quickly start using it, run the following command:

```
ghpew
```

Available commands:

```
ghpew repos
ghpew codespaces
ghpew help
```

## Why?

Have you ever had too much fun with the GitHub API and ended up creating too many dummy repos? Me too 😅!

I made this little CLI tool to clean up repositories quickly. I'm planning to add some flags and regexp to delete in bulk in the future. [Let me know](http://twitter.com/adrianmg) if that sounds interesting to you.
Expand All @@ -40,20 +51,24 @@ Do you want to know more? [Visit the official website](https://adrianmato.com/pe
The important parts of the project are the following:

```
├── .github GitHub Actions workflows and repo settings
├── .github GitHub Actions workflows and repo settings
├── src
│   ├── config.js Contains the configuration manager
│   ├── github.js Business logic: authentication and API calls
│   ├── ui.js CLI interactions
│   └── utils.js Lightweight utility functions
├── test
│   └── test.js Test coverage with Mocha
├── .prettierrc Code formatting configuration
├── index.js The main thread of execution
├── README.md you're looking at it
│ ├── commands
│   │   ├── codespaces.js Contains the command to delete codespaces
│   │   └── repos.js Contains the command to delete repos
│   ├── config.js Contains the configuration manager
│   ├── github.js Business logic: authentication and API calls
│   ├── ui.js CLI interactions
│   └── utils.js Lightweight utility functions
├── test
│   └── test.js Test coverage with Mocha
├── .prettierrc Code formatting configuration
├── index.js The main thread of execution
├── README.md you're looking at it
```

To **set up your environment** to develop this tool, run:

- `npm install`
- `node index`

Expand All @@ -62,16 +77,20 @@ You can also run `node index DEV=true CLIENT_ID=<YOUR_TESTING_CLIENT_ID>` if you
All the tests are written with [mocha](https://mochajs.org/) and can be run with `npm test`.

## TODO
- `--force` flag to avoid confirmation
- `--regex` flag to delete repos matching a regex
- `--list` flag to delete repos from a comma-separated list

- TODO: `--force` flag to avoid confirmation
- TODO: `--regex` flag to delete repos matching a regex
- TODO: `--list` flag to delete repos from a comma-separated list
- TODO: `--archive` and `-a` flag to [archive repositories](https://github.com/adrianmg/github-pewpew/issues/34) instead of deleting
- TODO: `ghpew gists` command to [delete gists](https://github.com/adrianmg/github-pewpew/issues/36)

## Questions? Ideas? Bugs?

If you run into any issues or you'd like to share your thoughts, feel free to [open an issue](https://github.com/adrianmg/github-pewpew/issues) in this repository or hit me up on [Twitter](https://twitter.com/adrianmg).

## Contributions
Logo designed by [Rapha Lopes](https://twitter.com/raphaellopesph). Thanks to [@sergiou87](https://github.com/sergiou87), [@zschiller](https://github.com/zschiller), and [@mamuso](https://github.com/mamuso) for contributing with their feedback and ideas 🙇‍♂️.

Logo designed by [Rapha Lopes](https://twitter.com/raphaellopesph). Thanks to [@sergiou87](https://github.com/sergiou87), [@zschiller](https://github.com/zschiller), [@mamuso](https://github.com/mamuso), and [@anishde12020](https://github.com/anishde12020) for contributing with their feedback and ideas 🙇‍♂️.

## License

Expand Down
64 changes: 34 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
#!/usr/bin/env node
const Config = require('./src/config');
const Github = require('./src/github');
const UI = require('./src/ui');

UI.printWelcome();
import Config from './src/config.js';
import Github from './src/github.js';
import UI from './src/ui.js';

import reposCommand from './src/commands/repos.js';
import codespacesCommand from './src/commands/codespaces.js';

main().then((exitCode) => {
process.exit(exitCode);
});
UI.printWelcome();

async function main() {
const main = async () => {
try {
if (!Config.load()) {
const token = await UI.promptAuth();
Config.save(token);
}

const repositories = await UI.getRepositories();
if (!repositories) {
Config.deleteFile();
return await main();
}

let res = await UI.promptSelectRepositories(repositories);
if (res.repos.length === 0) {
UI.printNoReposSelected();

return 0;
}

const reposToDelete = res.repos;
const repoCount = reposToDelete.length;
res = await UI.promptConfirmDelete(repoCount);

if (res.confirmDelete === 'Yes') {
await UI.deleteRepositories(reposToDelete);
} else {
UI.printNoReposDeleted();
const command = process.argv[2];

switch (command) {
case 'repos':
case 'repo':
case 'repository':
case 'repositories':
await reposCommand();
break;
case 'codespaces':
case 'codespace':
await codespacesCommand();
break;
case 'help':
UI.printHelp();
break;
default:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is right in order to avoid breaking changes in how the tool is executed. However, I think this could be improved. For example, if anyone executes something like this:

ghpew any-unknown-command

The script will execute the reposCommand. Maybe we could change this behavior to print the help:

default:
  if (!command) await reposCommand();
  else UI.printHelp(); // unknown command

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ideally, it should be tested too...

Copy link
Copy Markdown
Contributor Author

@AnishDe12020 AnishDe12020 Aug 4, 2022

Choose a reason for hiding this comment

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

That makes sense, I have added the check (5acd3ec)

image

For the label part, I have made this utility function -

const labels = {
  repos: { singular: 'repository', plural: 'respositories' },
  codespaces: { singular: 'codespace', plural: 'codespaces' },
};

const getLabel = (type, count) => {
  const { singular, plural } = labels[type];

  return count > 1 ? plural : singular;
};

(51ecf43)

The code is much more cleaner now, thanks for the feedback :)

if (!command) {
// await reposCommand();
UI.printHelp();
break;
}
UI.printHelp();
}
} catch (error) {
if (error instanceof Github.AuthError || error instanceof Github.ScopesError) {
Expand All @@ -48,4 +50,6 @@ async function main() {
UI.printError(error);
return;
}
}
};

main();
Loading