Skip to content

Commit

Permalink
chore: fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardhyan committed Mar 20, 2023
1 parent 1411419 commit 0a5a32d
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
# https://github.com/SonarSource/sonarqube-scan-action
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@master
with:
args: >
-Dsonar.exclusions=lib/**,dist/**
env:
GITHUB_TOKEN: ${{ github.token }}
SONAR_TOKEN: ${{ secrets.sonar_token }}
Expand Down
18 changes: 9 additions & 9 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import {ReleaseValidator} from "./ReleaseValidator";
import {ActionSkipper} from "./ActionSkipper";

export class Action {
private inputs: Inputs
private outputs: Outputs
private releases: Releases
private uploader: ArtifactUploader
private artifactDestroyer: ArtifactDestroyer
private skipper: ActionSkipper
private readonly inputs: Inputs
private readonly outputs: Outputs
private readonly releases: Releases
private readonly uploader: ArtifactUploader
private readonly artifactDestroyer: ArtifactDestroyer
private readonly skipper: ActionSkipper

private releaseValidator: ReleaseValidator
private readonly releaseValidator: ReleaseValidator

constructor(inputs: Inputs,
outputs: Outputs,
Expand Down Expand Up @@ -104,7 +104,7 @@ export class Action {

private static noPublishedRelease(error: any): boolean {
const githubError = new GithubError(error)
return githubError.status == 404
return githubError.status === 404
}

private async updateDraftOrCreateRelease(): Promise<CreateReleaseResponse | UpdateReleaseResponse> {
Expand All @@ -120,7 +120,7 @@ export class Action {
const tag = this.inputs.tag
const response = await this.releases.listReleases()
const releases = response.data
const draftRelease = releases.find(release => release.draft && release.tag_name == tag)
const draftRelease = releases.find(release => release.draft && release.tag_name === tag)

return draftRelease?.id
}
Expand Down
6 changes: 3 additions & 3 deletions src/ActionSkipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface ActionSkipper {
}

export class ReleaseActionSkipper {
constructor(private skipIfReleaseExists: boolean,
private releases: Releases,
private tag: string) {
constructor(private readonly skipIfReleaseExists: boolean,
private readonly releases: Releases,
private readonly tag: string) {
}

async shouldSkip(): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/ArtifactDestroyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ArtifactDestroyer {
}

export class GithubArtifactDestroyer implements ArtifactDestroyer {
constructor(private releases: Releases) {
constructor(private readonly releases: Releases) {
}

async destroyArtifacts(releaseId: number): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/ArtifactGlobber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ArtifactGlobber {
}

export class FileArtifactGlobber implements ArtifactGlobber {
private globber: Globber
private readonly globber: Globber

constructor(globber: Globber = new FileGlobber()) {
this.globber = globber
Expand All @@ -30,7 +30,7 @@ export class FileArtifactGlobber implements ArtifactGlobber {

private globPattern(pattern: string, errorsFailBuild: boolean): [string, string[]] {
const paths = this.globber.glob(pattern)
if (paths.length == 0) {
if (paths.length === 0) {
if (errorsFailBuild) {
FileArtifactGlobber.throwGlobError(pattern)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/ArtifactPathValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {statSync} from "fs";

export class ArtifactPathValidator {
private readonly errorsFailBuild: boolean;
private paths: string[];
private readonly paths: string[];
private readonly pattern: string

constructor(errorsFailBuild: boolean, paths: string[], pattern: string) {
Expand All @@ -18,7 +18,7 @@ export class ArtifactPathValidator {
}

private verifyPathsNotEmpty() {
if (this.paths.length == 0) {
if (this.paths.length === 0) {
const message = `Artifact pattern:${this.pattern} did not match any files`
this.reportError(message)
}
Expand Down
6 changes: 3 additions & 3 deletions src/ArtifactUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export interface ArtifactUploader {

export class GithubArtifactUploader implements ArtifactUploader {
constructor(
private releases: Releases,
private replacesExistingArtifacts: boolean = true,
private throwsUploadErrors: boolean = false,
private readonly releases: Releases,
private readonly replacesExistingArtifacts: boolean = true,
private readonly throwsUploadErrors: boolean = false,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/GithubError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {GithubErrorDetail} from "./GithubErrorDetail"

export class GithubError {
private error: any
private readonly error: any
private readonly githubErrors: GithubErrorDetail[]

constructor(error: any) {
Expand All @@ -23,7 +23,7 @@ export class GithubError {
}

hasErrorWithCode(code: String): boolean {
return this.githubErrors.some((err) => err.code == code)
return this.githubErrors.some((err) => err.code === code)
}

toString(): string {
Expand All @@ -42,7 +42,7 @@ export class GithubError {
}

private remediation(): String {
if (this.status == 404) {
if (this.status === 404) {
return "\nMake sure your github token has access to the repo and has permission to author releases"
}
return ""
Expand Down
2 changes: 1 addition & 1 deletion src/GithubErrorDetail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class GithubErrorDetail {
private error: any;
private readonly error: any;

constructor(error: any) {
this.error = error
Expand Down
66 changes: 42 additions & 24 deletions src/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export interface Inputs {
}

export class CoreInputs implements Inputs {
private artifactGlobber: ArtifactGlobber
private context: Context
private readonly artifactGlobber: ArtifactGlobber
private readonly context: Context

constructor(artifactGlobber: ArtifactGlobber, context: Context) {
this.artifactGlobber = artifactGlobber
Expand All @@ -41,7 +41,7 @@ export class CoreInputs implements Inputs {

get allowUpdates(): boolean {
const allow = core.getInput('allowUpdates')
return allow == 'true'
return allow === 'true'
}

get artifacts(): Artifact[] {
Expand All @@ -62,7 +62,7 @@ export class CoreInputs implements Inputs {

get artifactErrorsFailBuild(): boolean {
const allow = core.getInput('artifactErrorsFailBuild')
return allow == 'true'
return allow === 'true'
}

private get body(): string | undefined {
Expand All @@ -81,30 +81,36 @@ export class CoreInputs implements Inputs {

get createdDraft(): boolean {
const draft = core.getInput('draft')
return draft == 'true'
return draft === 'true'
}

get createdPrerelease(): boolean {
const preRelease = core.getInput('prerelease')
return preRelease == 'true'
return preRelease === 'true'
}

get createdReleaseBody(): string | undefined {
if (CoreInputs.omitBody) return undefined
if (CoreInputs.omitBody) {
return undefined
}

return this.body
}

private static get omitBody(): boolean {
return core.getInput('omitBody') == 'true'
return core.getInput('omitBody') === 'true'
}

get createdReleaseName(): string | undefined {
if (CoreInputs.omitName) return undefined
if (CoreInputs.omitName) {
return undefined
}

return this.name
}

private static get omitName(): boolean {
return core.getInput('omitName') == 'true'
return core.getInput('omitName') === 'true'
}

get commit(): string | undefined {
Expand Down Expand Up @@ -134,15 +140,15 @@ export class CoreInputs implements Inputs {

get generateReleaseNotes(): boolean {
const generate = core.getInput('generateReleaseNotes')
return generate == 'true'
return generate === 'true'
}

get makeLatest(): string {
return core.getInput('makeLatest')
}

get owner(): string {
let owner = core.getInput('owner')
const owner = core.getInput('owner')
if (owner) {
return owner
}
Expand All @@ -151,15 +157,15 @@ export class CoreInputs implements Inputs {

get removeArtifacts(): boolean {
const removes = core.getInput('removeArtifacts')
return removes == 'true'
return removes === 'true'
}
get replacesArtifacts(): boolean {
const replaces = core.getInput('replacesArtifacts')
return replaces == 'true'
return replaces === 'true'
}

get repo(): string {
let repo = core.getInput('repo')
const repo = core.getInput('repo')
if (repo) {
return repo
}
Expand Down Expand Up @@ -190,43 +196,55 @@ export class CoreInputs implements Inputs {
}

get updatedDraft(): boolean | undefined {
if (CoreInputs.omitDraftDuringUpdate) return undefined
if (CoreInputs.omitDraftDuringUpdate) {
return undefined
}

return this.createdDraft
}

private static get omitDraftDuringUpdate(): boolean {
return core.getInput('omitDraftDuringUpdate') == 'true'
return core.getInput('omitDraftDuringUpdate') === 'true'
}

get updatedPrerelease(): boolean | undefined {
if (CoreInputs.omitPrereleaseDuringUpdate) return undefined
if (CoreInputs.omitPrereleaseDuringUpdate) {
return undefined
}

return this.createdPrerelease
}

private static get omitPrereleaseDuringUpdate(): boolean {
return core.getInput('omitPrereleaseDuringUpdate') == 'true'
return core.getInput('omitPrereleaseDuringUpdate') === 'true'
}

get updatedReleaseBody(): string | undefined {
if (CoreInputs.omitBody || CoreInputs.omitBodyDuringUpdate) return undefined
if (CoreInputs.omitBody || CoreInputs.omitBodyDuringUpdate) {
return undefined
}

return this.body
}

private static get omitBodyDuringUpdate(): boolean {
return core.getInput('omitBodyDuringUpdate') == 'true'
return core.getInput('omitBodyDuringUpdate') === 'true'
}

get updatedReleaseName(): string | undefined {
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) {
return undefined
}

return this.name
}

get updateOnlyUnreleased(): boolean {
return core.getInput('updateOnlyUnreleased') == 'true'
return core.getInput('updateOnlyUnreleased') === 'true'
}

private static get omitNameDuringUpdate(): boolean {
return core.getInput('omitNameDuringUpdate') == 'true'
return core.getInput('omitNameDuringUpdate') === 'true'
}

stringFromFile(path: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/ReleaseValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class ReleaseValidator {
constructor(private updateOnlyUnreleased: boolean) {
constructor(private readonly updateOnlyUnreleased: boolean) {
}

validateReleaseUpdate(releaseResponse: ReleaseStageArguments) {
Expand Down
10 changes: 5 additions & 5 deletions src/Releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
draft: boolean = false,
generateReleaseNotes: boolean = false,
makeLatest?: string,
name?: string,
prerelease?: boolean
prerelease: boolean = false
): Promise<CreateReleaseResponse> {
// noinspection TypeScriptValidateJSTypes
return this.git.rest.repos.createRelease({
Expand Down Expand Up @@ -137,10 +137,10 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
draft: boolean = false,
makeLatest?: string,
name?: string,
prerelease?: boolean
prerelease: boolean = false
): Promise<UpdateReleaseResponse> {
// noinspection TypeScriptValidateJSTypes
return this.git.rest.repos.updateRelease({
Expand Down

0 comments on commit 0a5a32d

Please sign in to comment.