Skip to content

Commit

Permalink
feat: using default username from token by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfreud committed Apr 22, 2024
1 parent ef22187 commit 8429b84
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
23 changes: 0 additions & 23 deletions .TODO

This file was deleted.

25 changes: 25 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Todo

- Replace OctokitResponse<any> by proper typing!
- Consider writing tests (unit tests and whatnot)
- Add warning about gitbub's rate limit
- Changeset to major version when basic cli is active
- Octokit
- Check if user is authenticated
- Add a mini logger lib file
- Handle verbose properly

## From feedback

- [x] use more branches (e.g. `main`, `develop`, `feature/...`, `bugfix/...`), moost of them will be temporary till reviewing process
- [] see if owner can be retrieved from GitHub access token, use default as username
- [] better README
- [] donner plus d'infos pour l'access token, permettre d'obtenir un lien pour le générer avec peut-etre en query params de quoi remplir le formulaire avec le minimum requis pour l'access token
- [] preciser les permissions accordees a quirgo sont les permissions minimales requises
- [] donner la possibilite de stocker le token, voire meme plusieurs
- [] set verbose to false at default in configuration
- [] mutual exclusion of --json && --env
- [] simplify the usage of --verbose (specially when default is false)

-- CLI --
Other: [gulp, jest]
36 changes: 30 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,27 @@ program.on("option:verbose", () => {
config.verbose = true;
});

program.on("option:token", (token) => {
if (!repoManager) repoManager = new RepoManager(token);
program.on("option:token", async (token) => {
try {
if (!repoManager) repoManager = new RepoManager(token);

// DOC: note that this will be default if no --owner option is detected
config.repositoryOwner = (await repoManager.getUserLogin()) || "";

if (config.verbose) {
console.log(
chalk.cyan("-> Using"),
chalk.bgBlueBright(config.repositoryOwner),
chalk.cyan("as default repository owner")
);
}
} catch (err: any) {
console.error(
chalk.red("Impossible to authenticate using the GitHub Access Token")
);
console.error(chalk.red(err));
process.exit(-1);
}
});

program.on("option:repo", (repo) => {
Expand All @@ -276,6 +295,11 @@ program.on("option:json", (json) => {
parsedKeyValues = jsonParser(json, { verbose: config.verbose || false });
});

program.action(() => {
program.outputHelp();
process.exit(0);
});

program.parse(process.argv);

/**
Expand Down Expand Up @@ -317,7 +341,7 @@ async function fn() {
}
}

// If no command is provided, show help
if (!process.argv.slice(2).length) {
program.outputHelp();
}
// // If no command is provided, show help
// if (!process.argv.slice(2).length) {
// program.outputHelp();
// }
5 changes: 5 additions & 0 deletions src/lib/repository-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class RepoManager {
this.app = new Octokit({ auth: githubAccessToken });
}

public async getUserLogin(): Promise<string | null> {
const user = await this.app.rest.users.getAuthenticated();
return user.data.login;
}

/**
* List variables in the repository for GitHub Actions.
* @param {Configuration} config The configuration object containing repository details.
Expand Down

0 comments on commit 8429b84

Please sign in to comment.