Skip to content

Commit

Permalink
🚧Rename client functions (#97)
Browse files Browse the repository at this point in the history
* Start work for issue #77

* refactor!: rename release client function

* refactor!: rename label client function

* refactor!: rename pr client function named openPullRequestExists

* refactor!: rename pr client function named closedPullRequestExists

* refactor: rename private function

* refactor!: rename pr client function named pullRequestExists

* refactor!: rename issue client function named openIssueExists

* refactor!: rename issue client function named closedIssueExists

* refactor!: rename issue client function named issueExists

* refactor!: rename repo client function named repoVariableExists

* refactor!: rename tag client function named tagExists

* chore!: remove packageExists function

* refactor!: rename nuget client function named packageWithVersionExists
  • Loading branch information
CalvinWilkinson authored Oct 15, 2024
1 parent fe672b6 commit e6f9bad
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/cicd/scripts/version-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (!await repoClient.exists()) {

const tagClient: TagClient = new TagClient(ownerName, repoName, token);

if (await tagClient.tagExists(version)) {
if (await tagClient.exists(version)) {
const errorMsg = `The tag '${version}' already exists.`;
Utils.printError(errorMsg);
Deno.exit(1);
Expand Down
8 changes: 4 additions & 4 deletions GitHubClients/IssueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class IssueClient extends GitHubClient {
Guard.isLessThanOne(issueNumber, "addLabel", "issueNumber");

// First check that the label trying to be added exists in the repo
const labelDoesNotExist = !(await this.labelClient.labelExists(label));
const labelDoesNotExist = !(await this.labelClient.exists(label));

if (labelDoesNotExist) {
const labelsUrl = `https://github.com/KinsonDigital/${super.repoName}/labels`;
Expand Down Expand Up @@ -297,7 +297,7 @@ export class IssueClient extends GitHubClient {
* @returns True if the issue exists, otherwise false.
* @throws An {@link AuthError} or {@link IssueError}.
*/
public async issueExists(issueNumber: number): Promise<boolean> {
public async exists(issueNumber: number): Promise<boolean> {
Guard.isLessThanOne(issueNumber, "issueExists", "issueNumber");

return await this.openOrClosedIssueExists(issueNumber, IssueOrPRState.any);
Expand All @@ -310,7 +310,7 @@ export class IssueClient extends GitHubClient {
* @returns True if the issue exists and is open, otherwise false.
* @throws An {@link AuthError} or {@link IssueError}.
*/
public async openIssueExists(issueNumber: number): Promise<boolean> {
public async openExists(issueNumber: number): Promise<boolean> {
Guard.isLessThanOne(issueNumber, "openIssueExist", "issueNumber");

return await this.openOrClosedIssueExists(issueNumber, IssueOrPRState.open);
Expand All @@ -323,7 +323,7 @@ export class IssueClient extends GitHubClient {
* @returns True if the issue exists and is open, otherwise false.
* @throws An {@link AuthError} or {@link IssueError}.
*/
public async closedIssueExists(issueNumber: number): Promise<boolean> {
public async closedExists(issueNumber: number): Promise<boolean> {
Guard.isLessThanOne(issueNumber, "closedIssueExist", "issueNumber");

return await this.openOrClosedIssueExists(issueNumber, IssueOrPRState.closed);
Expand Down
2 changes: 1 addition & 1 deletion GitHubClients/LabelClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class LabelClient extends GitHubClient {
* @remarks Does not require authentication.
* @throws An {@link AuthError} or {@link LabelError}.
*/
public async labelExists(label: string): Promise<boolean> {
public async exists(label: string): Promise<boolean> {
Guard.isNothing(label, "labelExists", "label");

const foundLabels = await this.getAllDataUntil(
Expand Down
2 changes: 1 addition & 1 deletion GitHubClients/MilestoneClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class MilestoneClient extends GitHubClient {
* @remarks Does not require authentication.|
* @throws An {@link AuthError} or {@link MilestoneError}.
*/
public async milestoneExists(milestoneName: string): Promise<boolean> {
public async exists(milestoneName: string): Promise<boolean> {
Guard.isNothing(milestoneName, "milestoneExists", "milestoneName");

milestoneName = milestoneName.trim();
Expand Down
16 changes: 8 additions & 8 deletions GitHubClients/PullRequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class PullRequestClient extends GitHubClient {
}

// First check that the label trying to be added exists in the repo
const labelDoesNotExist = !(await this.labelClient.labelExists(label));
const labelDoesNotExist = !(await this.labelClient.exists(label));

if (labelDoesNotExist) {
const labelsUrl = Utils.buildLabelsUrl(this.ownerName, this.repoName);
Expand Down Expand Up @@ -236,7 +236,7 @@ export class PullRequestClient extends GitHubClient {
* 1. The {@link AuthError} when the request is unauthorized.
* 2. The {@link PullRequestError} when something goes wrong with getting all of the pull requests.
*/
public async pullRequestExists(prNumber: number): Promise<boolean> {
public async exists(prNumber: number): Promise<boolean> {
Guard.isLessThanOne(prNumber, "pullRequestExists", "prNumber");

// REST API Docs: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
Expand Down Expand Up @@ -276,10 +276,10 @@ export class PullRequestClient extends GitHubClient {
* 1. The {@link AuthError} when the request is unauthorized.
* 2. The {@link PullRequestError} when something goes wrong with getting all of the pull requests.
*/
public async openPullRequestExists(prNumber: number): Promise<boolean> {
public async openExists(prNumber: number): Promise<boolean> {
Guard.isLessThanOne(prNumber, "openPullRequestExists", "issueNumber");

return await this.openOrClosedPullRequestExists(prNumber, IssueOrPRState.open);
return await this.openOrClosedExists(prNumber, IssueOrPRState.open);
}

/**
Expand All @@ -294,7 +294,7 @@ export class PullRequestClient extends GitHubClient {
public async updatePullRequest(prNumber: number, prRequestData: IssueOrPRRequestData): Promise<void> {
Guard.isLessThanOne(prNumber, "updatePullRequest", "prNumber");

const prDoesNotExist = !(await this.pullRequestExists(prNumber));
const prDoesNotExist = !(await this.exists(prNumber));

if (prDoesNotExist) {
const errorMsg = `A pull request with the number '${prNumber}' does not exist in the repo '${this.repoName}'.`;
Expand Down Expand Up @@ -384,10 +384,10 @@ export class PullRequestClient extends GitHubClient {
* 1. The {@link AuthError} when the request is unauthorized.
* 2. The {@link PullRequestError} when something goes wrong with getting all of the pull requests.
*/
public async closedPullRequestExists(prNumber: number): Promise<boolean> {
public async closedExists(prNumber: number): Promise<boolean> {
Guard.isLessThanOne(prNumber, "closedPullRequestExists", "issueNumber");

return await this.openOrClosedPullRequestExists(prNumber, IssueOrPRState.closed);
return await this.openOrClosedExists(prNumber, IssueOrPRState.closed);
}

/**
Expand Down Expand Up @@ -453,7 +453,7 @@ export class PullRequestClient extends GitHubClient {
* 1. The {@link AuthError} when the request is unauthorized.
* 2. The {@link PullRequestError} when something goes wrong with getting all of the pull requests.
*/
private async openOrClosedPullRequestExists(
private async openOrClosedExists(
prNumber: number,
state: IssueOrPRState,
): Promise<boolean> {
Expand Down
4 changes: 2 additions & 2 deletions GitHubClients/RepoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class RepoClient extends GitHubClient {
* 2. An {@link AuthError} if there was a problem with the authentication.
* 3. The {@link RepoError} if the there was a problem getting all of the repository variables.
*/
public async repoVariableExists(variableName: string): Promise<boolean> {
public async variableExists(variableName: string): Promise<boolean> {
Guard.isNothing(variableName, "repoVariableExists", "variableName");

const variables = await this.getVariables();
Expand All @@ -277,7 +277,7 @@ export class RepoClient extends GitHubClient {
Guard.isNothing(variableName, funcName, "variableName");
Guard.isNothing(variableValue, funcName, "variableValue");

if (!(await this.repoVariableExists(variableName))) {
if (!(await this.variableExists(variableName))) {
throw new RepoError(`The variable '${variableName}' does not exist for the repository '${this.repoName}'.`);
}

Expand Down
2 changes: 1 addition & 1 deletion GitHubClients/TagClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class TagClient extends GitHubClient {
* 2. An {@link AuthError} if the request was unauthorized.
* 3. The {@link TagError} if there was an issue getting the tags.
*/
public async tagExists(tagName: string): Promise<boolean> {
public async exists(tagName: string): Promise<boolean> {
Guard.isNothing(tagName, "tagExists", "tagName");

tagName = tagName.trim();
Expand Down
40 changes: 11 additions & 29 deletions PackageClients/NuGetClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { WebApiClient } from "../core/WebApiClient.ts";
import { Guard } from "../core/Guard.ts";
import { NuGetHttpStatusCodes } from "../core/Enums.ts";
import { NuGetError } from "./Errors/NuGetError.ts";
import { Utils } from "../deps.ts";

/**
* References:
Expand All @@ -24,33 +25,6 @@ export class NuGetClient extends WebApiClient {
this.updateOrAddHeader("Accept", "json");
}

/**
* Checks if a package that matches the given {@link packageName} exists in the NuGet registry.
* @param packageName The name of the NuGet package.
* @returns True if the package exists, otherwise false.
* @throws The {@link NuGetError} if there was an issue checking for the package.
*/
public async packageExists(packageName: string): Promise<boolean> {
Guard.isNothing(packageName, "packageExists", "packageName");

packageName = packageName.trim().toLowerCase();
const url = this.buildUrl(packageName);

const response: Response = await this.requestGET(url);
const statusCode: NuGetHttpStatusCodes = response.status as NuGetHttpStatusCodes;

if (this.statusCodeValid(statusCode)) {
return statusCode === NuGetHttpStatusCodes.SuccessWithResponseBody;
} else {
const errorMsg = this.buildErrorMsg(
`There was an issue checking for the '${packageName}' NuGet package.`,
response,
);

throw new NuGetError(errorMsg);
}
}

/**
* Gets all of the versions for a NuGet package that matches the given {@link packageName}.
* @param packageName The name of the NuGet package.
Expand Down Expand Up @@ -87,13 +61,17 @@ export class NuGetClient extends WebApiClient {
* @returns True if the package exists with the given version, otherwise false.
* @throws The {@link NuGetError} if there was an issue checking for a specific package version.
*/
public async packageWithVersionExists(packageName: string, version: string): Promise<boolean> {
public async exists(packageName: string, version?: string): Promise<boolean> {
const funcName = "packageWithVersionExists";
Guard.isNothing(packageName, funcName, "packageName");
Guard.isNothing(packageName, funcName, "version");

packageName = packageName.trim().toLowerCase();
version = version.trim().toLowerCase();

if (!Utils.isNothing(version)) {
version = version.trim().toLowerCase();
version = version.startsWith("v") ? version.slice(1) : version;
}

const url = this.buildUrl(packageName);

Expand All @@ -102,6 +80,10 @@ export class NuGetClient extends WebApiClient {

if (this.statusCodeValid(statusCode)) {
if (statusCode === NuGetHttpStatusCodes.SuccessWithResponseBody) {
if (Utils.isNothing(version)) {
return true;
}

const versions = <string[]> (await this.getResponseData<{ versions: string[] }>(response))
.versions.map((v: string) => v.toLowerCase());

Expand Down

0 comments on commit e6f9bad

Please sign in to comment.