Skip to content

Commit

Permalink
refactor: небольшой рефакторинг имен и структуры
Browse files Browse the repository at this point in the history
  • Loading branch information
alkoleft committed Jun 4, 2024
1 parent 9faf31d commit aeab85c
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 242 deletions.
8 changes: 4 additions & 4 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { debug } from 'console'
import { config } from 'dotenv'

import { GithubMerge } from '../src/github'
import { GithubReview } from '../src/github'

describe('github', () => {
config()
Expand All @@ -21,15 +21,15 @@ describe('github', () => {
// })

it('getQualityDiscussion', async () => {

Check warning on line 23 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions

Check warning on line 23 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
const githubMR = new GithubMerge({
const githubMR = new GithubReview({
pull_number: 9,
token: token,

Check failure on line 26 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 26 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
repo: repo

Check failure on line 27 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 27 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
})
debug(await githubMR.getQualityDiscussion())
})
it('getReviews', async () => {

Check warning on line 31 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions

Check warning on line 31 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
const githubMR = new GithubMerge({
const githubMR = new GithubReview({
pull_number: 9,
token: token,

Check failure on line 34 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 34 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
repo: repo

Check failure on line 35 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 35 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
Expand All @@ -38,7 +38,7 @@ describe('github', () => {
})

it('getReviewComments', async () => {

Check warning on line 40 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions

Check warning on line 40 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
const githubMR = new GithubMerge({
const githubMR = new GithubReview({
pull_number: 9,
token: token,

Check failure on line 43 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 43 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
repo: repo

Check failure on line 44 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 44 in __tests__/github.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
Expand Down
12 changes: 6 additions & 6 deletions __tests__/publisher.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from 'dotenv'

import { Publisher } from '../src/publisher'
import { ReviewPublisher } from '../src/publisher/review'
import { Sonar } from '../src/sonar'
import { GithubMerge } from '../src/github'
import { GithubReview } from '../src/github'

describe('main.ts', () => {
config()
Expand All @@ -19,12 +19,12 @@ describe('main.ts', () => {
branchPluginEnabled: true,
pull_number: 370
})
const github = new GithubMerge({
const github = new GithubReview({
repo: repo,

Check failure on line 23 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 23 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
pull_number: 9,
token: token

Check failure on line 25 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 25 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
})
const publisher = new Publisher(sonar, github)
const publisher = new ReviewPublisher(sonar, github)
await publisher.generateReport()
})
it('publishIssues', async () => {

Check warning on line 30 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions

Check warning on line 30 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
Expand All @@ -34,12 +34,12 @@ describe('main.ts', () => {
branchPluginEnabled: true,
pull_number: 370
})
const github = new GithubMerge({
const github = new GithubReview({
repo: repo,

Check failure on line 38 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 38 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
pull_number: 370,
token: token

Check failure on line 40 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 40 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
})
const publisher = new Publisher(sonar, github)
const publisher = new ReviewPublisher(sonar, github)
const status = {
projectStatus: {
status: 'UNKNOWN',
Expand Down
127 changes: 76 additions & 51 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/github/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ReviewComments =
Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/comments']['response']['data']
export type ReviewComment = ReviewComments[0]

export class GithubMerge {
export class GithubReview {
pull_number: number
octokit: InstanceType<typeof GitHub>
repo: Repo
Expand Down
31 changes: 16 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as core from '@actions/core'
import { Sonar } from './sonar'
import { SonarProperties } from './sonar/properties'
import { GithubMerge } from './github'
import { GithubReview } from './github'
import githubAutoConfig from './github/autoconfig'
import { Repo } from './model/entity'
import { Publisher } from './publisher'
import * as PublisherFactory from './publisher'

/**
* The main function for the action.
Expand All @@ -15,39 +15,40 @@ export async function run(): Promise<void> {
const githubConfig = githubAutoConfig()
const sonarConfig = new SonarProperties({ projectDir: process.cwd() })

const args: Args = {
sonarToken: core.getInput('sonar_token') || process.env.SONAR_TOKEN || '',
core.debug(`generate report`)

generateReport({
sonarToken: core.getInput('sonar_token') || process.env.SONAR_TOKEN,
sonarURL: core.getInput('sonar_url') || sonarConfig.getSonarURL(),
sonarProjectKey:
core.getInput('sonar_project') || sonarConfig.getProjectKey(),
sonarBranchPlugin: core.getBooleanInput('sonar_branch_plugin'),
repo: githubConfig.repo,
mergeID:
parseInt(core.getInput('pull_number')) || githubConfig.pr?.number || 9,
parseInt(core.getInput('pull_number')) || githubConfig.pr?.number,
githubToken:
core.getInput('github_token') || process.env.GITHUB_TOKEN || ''
}
core.debug(`generate report`)

generateReport(args)
})
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
}
}

interface Args {
export async function generateReport(args: {
sonarToken?: string
sonarURL: string
sonarProjectKey: string
sonarBranchPlugin: boolean
mergeID: number
mergeID?: number
githubToken: string
repo: Repo
}
}) {
if (!args.mergeID) {
throw 'You need to specify pull_number'
}

export async function generateReport(args: Args) {
const github = new GithubMerge({
const github = new GithubReview({
token: args.githubToken,
pull_number: args.mergeID,
repo: args.repo
Expand All @@ -61,6 +62,6 @@ export async function generateReport(args: Args) {
pull_number: args.mergeID
})

const publisher = new Publisher(sonar, github)
const publisher = PublisherFactory.create(sonar, github)
await publisher.generateReport()
}
Loading

0 comments on commit aeab85c

Please sign in to comment.