Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Update clients to check for authentication issues #10

Merged
merged 54 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
be9e39e
Start work for issue #9
CalvinWilkinson Nov 10, 2023
d65dc8f
tests: create test to check if error is thrown
CalvinWilkinson Nov 10, 2023
6241fe7
Merge branch 'main' into feature/9-update-client-auth
CalvinWilkinson Nov 17, 2023
f419d2d
Merge branch 'preview' into feature/9-update-client-auth
CalvinWilkinson May 12, 2024
c289fec
BREAKING CHANGE: changed return type of ReleaseClient.getReleases
CalvinWilkinson May 12, 2024
969471e
cleanup: remove dead code
CalvinWilkinson May 12, 2024
f74e000
refactor!: change the param name to a better name
CalvinWilkinson May 12, 2024
a6de30b
refactor!: change the param name to a better name
CalvinWilkinson May 12, 2024
a4a9075
chore: improved internal function
CalvinWilkinson May 12, 2024
e76020c
enhance!: add a new error type that can be used to represent an auth …
CalvinWilkinson May 12, 2024
2981ccc
chore: adjust to unauthorized
CalvinWilkinson May 13, 2024
a75021f
chore: readjust return types
CalvinWilkinson May 13, 2024
aeffaf8
chore: improve func docs
CalvinWilkinson May 13, 2024
7a2bd57
chore: add param checks to ctor
CalvinWilkinson May 13, 2024
83520c2
docs: add throws docs
CalvinWilkinson May 13, 2024
3e87ad4
chore: add param checks with docs
CalvinWilkinson May 13, 2024
1fa1dde
fix: fix an issue with error msg containing an incorrect issue url
CalvinWilkinson May 13, 2024
f6472ec
fix: fix a bug with getting issues filtered by labels
CalvinWilkinson May 13, 2024
21417c2
enhance: update issue client to throw auth errors
CalvinWilkinson May 13, 2024
a619f9d
chore: remove bad credentials error
CalvinWilkinson May 13, 2024
eb07ab8
chore: replace bad credential error with auth error
CalvinWilkinson May 13, 2024
5270c3b
enhance: throw auth error for git client functions
CalvinWilkinson May 13, 2024
8b64eff
enhance: throw auth error with label client functions
CalvinWilkinson May 13, 2024
40e8dc7
refactor: improve label exists function
CalvinWilkinson May 13, 2024
0832125
refactor: improve func for getting issues and pull requests
CalvinWilkinson May 13, 2024
916be93
enhance: throw auth errors with milestone client functions
CalvinWilkinson May 13, 2024
db85c52
enhance: throw auth errors with org client
CalvinWilkinson May 13, 2024
8d3d894
refactor!: move the XError type to the correct location
CalvinWilkinson May 13, 2024
89c0e31
refactor!: move the NuGetError type to the correct location
CalvinWilkinson May 13, 2024
d1d24c9
refactor: add github error checks for the get all data functions
CalvinWilkinson May 13, 2024
6258224
docs: improve docs related to types of errors thrown
CalvinWilkinson May 13, 2024
76af3a0
refactor!: changed return type of getPullRequests func in the pr client
CalvinWilkinson May 13, 2024
84d609e
refactor!: changed return type of getIssues func in the issue client
CalvinWilkinson May 13, 2024
c842ac8
refactor: update funcs in milestone client due to issue and pr client…
CalvinWilkinson May 13, 2024
3b9963c
enhance: throw auth errors in pr client
CalvinWilkinson May 13, 2024
847b396
refactor: update code to meet coding standards
CalvinWilkinson May 13, 2024
437bf6b
deps: update deno lock
CalvinWilkinson May 13, 2024
39eb443
config: setup line ending settings to use only 'LF'
CalvinWilkinson May 14, 2024
95c661a
refactor!: change the name of the getOwnerRepos function
CalvinWilkinson May 14, 2024
fd90c59
refactor!: change the return type of the getAllRepos function
CalvinWilkinson May 14, 2024
e4373f2
refactor: rename private function
CalvinWilkinson May 14, 2024
3ec8790
chore: add check for other parameter
CalvinWilkinson May 14, 2024
62d267a
enhance: throw auth errors in repo client
CalvinWilkinson May 14, 2024
e0e26dc
refactor!: change return type of getTags function
CalvinWilkinson May 14, 2024
3335923
enhance: throw auth errors in tag client
CalvinWilkinson May 14, 2024
31af34e
enhance: throw auth errors in users client
CalvinWilkinson May 14, 2024
a882d8f
config: rename deno script from build to check
CalvinWilkinson May 14, 2024
9780bbc
refactor!: change return type of getWorkflowRuns function
CalvinWilkinson May 14, 2024
7c7f0e6
enhance: throw auth errors in workflow client
CalvinWilkinson May 14, 2024
eac5a41
ide: set title and color of vscode for project
CalvinWilkinson May 14, 2024
9d76032
refactor: fix equals operator
CalvinWilkinson May 14, 2024
7d6106f
refactor: fix not equals operators
CalvinWilkinson May 14, 2024
764278c
ci: force status checks
CalvinWilkinson May 14, 2024
864afa1
test: fix failing tests
CalvinWilkinson May 14, 2024
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
4 changes: 2 additions & 2 deletions .github/cicd/core/Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Directory {
extension = extension.trim();
extension = Utils.isNothing(extension) ? "*.*" : extension;

if (extension != "*.*") {
if (extension !== "*.*") {
extension = extension.startsWith("*.") ? extension.substring(1) : extension;

if (!extension.startsWith(".") || extension.length === 1) {
Expand All @@ -57,7 +57,7 @@ export class Directory {
dirPath = dirPath === "." || dirPath === "./" ? Deno.cwd() : dirPath;

for (const dirEntry of Deno.readDirSync(dirPath)) {
const entry = dirPath == "/"
const entry = dirPath === "/"
? dirPath + dirEntry.name
: dirPath + "/" + dirEntry.name;

Expand Down
11 changes: 11 additions & 0 deletions .github/cicd/playground.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
import { IssueOrPRState } from "../../core/Enums.ts";
import { IssueModel } from "../../deps.ts";
import { GitClient, IssueClient, LabelClient, MilestoneClient, OrgClient, TagClient } from "../../mod.ts";

const _token = Deno.args[0]; // NOTE: This is coming from the launch.config json file as an environment variable
const _rootRepoDirPath = Deno.args[1];

const client = new TagClient("KinsonDigital", "Velaptor", "_token");


const issues = await client.getAllTags();

debugger;
2 changes: 1 addition & 1 deletion .github/cicd/scripts/check-release-notes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Utils } from "../../../core/Utils.ts";
import { File } from "../core/File.ts";

if (Deno.args.length != 2) {
if (Deno.args.length !== 2) {
let errorMsg = `The required number of arguments is 2 but received ${Deno.args.length}.`;
errorMsg += `\nPlease provide the following arguments: version type, version.`;
Utils.printError(errorMsg);
Expand Down
4 changes: 2 additions & 2 deletions .github/cicd/scripts/version-checker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RepoClient, TagClient, UsersClient } from "../../../GitHubClients/mod.ts";
import { Utils } from "../../../core/Utils.ts";

if (Deno.args.length != 5) {
if (Deno.args.length !== 5) {
let errorMsg = `The required number of arguments is 5 but only ${Deno.args.length}.`;
errorMsg += `\nPlease provide the following arguments: version, owner name, repo name, and token.`;
Utils.printError(errorMsg);
Expand Down Expand Up @@ -42,7 +42,7 @@ if (await tagClient.tagExists(version)) {
Deno.exit(1);
}

if (versionType != "preview" && versionType != "production") {
if (versionType !== "preview" && versionType !== "production") {
const errorMsg = `The version type '${versionType}' is not valid. Valid values are 'preview' or 'production' version type.`;
Utils.printError(errorMsg);
Deno.exit(1);
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
},
"deno.enable": true,
"deno.lint": true,
"files.eol": "\n",
"window.title": "🦕KD_CLIENTS",
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#1a2519"
},
"[typescript]": {
"editor.insertSpaces": false,
"editor.tabSize": 4,
Expand Down
17 changes: 17 additions & 0 deletions GitHubClients/Errors/AuthError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Error thrown when there is an authentication error.
*/
export class AuthError extends Error {
/**
* Initializes a new instance of the {@link AuthError} class.
* @param message The message of the error.
*/
constructor(message?: string) {
const errorMessage = message === undefined
? "Authentication error occurred. Please check the GitHub token used and try again."
: message;

super(errorMessage);
this.name = "AuthError";
}
}
9 changes: 0 additions & 9 deletions GitHubClients/Errors/BadCredentialsError.ts

This file was deleted.

4 changes: 1 addition & 3 deletions GitHubClients/Errors/mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export { BadCredentialsError } from "./BadCredentialsError.ts";
export { AuthError } from "./AuthError.ts";
export { GitError } from "./GitError.ts";
export { IssueError } from "./IssueError.ts";
export { LabelError } from "./LabelError.ts";
export { MilestoneError } from "./MilestoneError.ts";
export { NuGetError } from "./NuGetError.ts";
export { OrganizationError } from "./OrganizationError.ts";
export { ProjectError } from "./ProjectError.ts";
export { PullRequestError } from "./PullRequestError.ts";
Expand All @@ -12,4 +11,3 @@ export { RepoError } from "./RepoError.ts";
export { TagError } from "./TagError.ts";
export { UsersError } from "./UsersError.ts";
export { WorkflowError } from "./WorkflowError.ts";
export { XError } from "./XError.ts";
39 changes: 25 additions & 14 deletions GitHubClients/GitClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQlClient } from "../deps.ts";
import { AuthError, GraphQlClient } from "../deps.ts";
import { createGetBranchesQuery } from "../core/GraphQl/Queries/GetBranchesQuery.ts";
import { Guard } from "../core/Guard.ts";
import { PageInfoModel } from "../deps.ts";
Expand All @@ -9,7 +9,6 @@ import { Utils } from "../deps.ts";
import { RepoClient } from "./RepoClient.ts";
import { getCreateBranchMutation } from "../core/GraphQl/Mutations/CreateBranchMutation.ts";
import { addCommitMutation } from "../core/GraphQl/Mutations/AddCommitMutation.ts";
import { OrganizationError } from "../deps.ts";
import { GitError } from "../deps.ts";

/**
Expand All @@ -24,6 +23,7 @@ export class GitClient extends GraphQlClient {
* @param ownerName The owner of the repository.
* @param repoName The name of the repository.
* @param token The GitHub token to use for authentication.
* @throws An {@link Error} if the parameters are undefined, null, or empty.
*/
constructor(ownerName: string, repoName: string, token: string) {
const funcName = "GitClient.Ctor";
Expand Down Expand Up @@ -68,15 +68,15 @@ export class GitClient extends GraphQlClient {
* Gets a branch with the given branch {@link name}.
* @param name The name of the branch.
* @returns The branch.
* @throws {@link OrganizationError} Thrown if the branch does not exist.
* @throws An {@link AuthError} or {@link GitError}.
*/
public async getBranch(name: string): Promise<GitBranchModel> {
Guard.isNothing(name, "getBranch", "name");

const branches: GitBranchModel[] = await this.getBranches((branch) => branch.name === name);

if (branches.length <= 0) {
throw new OrganizationError(`The branch '${name}' does not exist.`);
throw new GitError(`The branch '${name}' does not exist.`);
}

return branches.filter((branch) => branch.name === name)[0];
Expand All @@ -87,7 +87,7 @@ export class GitClient extends GraphQlClient {
* @param untilPredicate Used to determine when to stop getting branches.
* @returns The list of branches for the repository.
* @remarks If the {@link untilPredicate} is not provided, all branches will be returned.
* @throws The error {@link GitError} if an error occurs while getting branches.
* @throws An {@link AuthError} or {@link GitError}.
*/
public async getBranches(untilPredicate?: (branch: GitBranchModel) => boolean): Promise<GitBranchModel[]> {
const result: GitBranchModel[] = [];
Expand All @@ -103,7 +103,11 @@ export class GitClient extends GraphQlClient {

const responseData = await this.executeQuery(query);

if (responseData.errors != undefined) {
if (responseData instanceof AuthError) {
throw responseData;
}

if (responseData.errors !== undefined) {
const mainMsg = `The following errors occurred while getting branches for the repository '${super.repoName}'`;
const errorMsg = Utils.toErrorMessage(mainMsg, responseData);

Expand All @@ -125,8 +129,8 @@ export class GitClient extends GraphQlClient {
for (let i = 0; i < branches.length; i++) {
const branch = branches[i];

const stopPulling: boolean = untilPredicate != null &&
untilPredicate != undefined &&
const stopPulling: boolean = untilPredicate !== null &&
untilPredicate !== undefined &&
untilPredicate(branch);

result.push(branch);
Expand All @@ -144,6 +148,7 @@ export class GitClient extends GraphQlClient {
* Gets a value indicating whether or not a branch with the given branch {@link name} exists.
* @param name The name of the branch.
* @returns True if the branch exists; otherwise, false.
* @throws An {@link AuthError} or {@link GitError}.
*/
public async branchExists(name: string): Promise<boolean> {
Guard.isNothing(name, "branchExists", "name");
Expand All @@ -157,9 +162,7 @@ export class GitClient extends GraphQlClient {
* Creates a branch with the given {@link newBranchName} from a branch that matches the given {@link branchFromName}.
* @param newBranchName The name of the branch.
* @remarks Requires authentication.
* @throws The error {@link GitError} for the following reasons:
* 1. If the given {@link newBranchName} already exists.
* 2. If there was an issue creating the new branch.
* @throws An {@link AuthError} or {@link GitError}.
*/
public async createBranch(newBranchName: string, branchFromName: string): Promise<GitBranchModel> {
const funcName = "createBranch";
Expand All @@ -184,7 +187,11 @@ export class GitClient extends GraphQlClient {

const responseData = await this.executeQuery(mutation);

if (responseData.errors != undefined) {
if (responseData instanceof AuthError) {
throw responseData;
}

if (responseData.errors !== undefined) {
const mainMsg = `The following errors occurred while creating the branch '${newBranchName}'`;
const errorMsg = Utils.toErrorMessage(mainMsg, responseData);

Expand All @@ -204,7 +211,7 @@ export class GitClient extends GraphQlClient {
* Adds a commit with the given {@link commitMessage} to a branch with the given {@link branchName}.
* @param branchName The name of the branch.
* @param commitMessage The commit message.
* @throws The error {@link GitError} if the commit could not be added.
* @throws An {@link AuthError} or {@link GitError}.
*/
public async addCommit(branchName: string, commitMessage: string): Promise<void> {
const funcName = "addCommit";
Expand All @@ -217,7 +224,11 @@ export class GitClient extends GraphQlClient {

const response = await this.executeQuery(mutation);

if (response.errors != undefined) {
if (response instanceof AuthError) {
throw response;
}

if (response.errors !== undefined) {
const mainMsg = `The following errors occurred while adding a commit to the branch '${branchName}'`;
const errorMsg = Utils.toErrorMessage(mainMsg, response);

Expand Down
Loading
Loading