Skip to content

Commit

Permalink
alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
alkoleft committed Jun 3, 2024
1 parent 44de8a3 commit 7540b9b
Show file tree
Hide file tree
Showing 27 changed files with 7,420 additions and 235 deletions.
48 changes: 48 additions & 0 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { debug } from 'console'
import { config } from 'dotenv'

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

describe('github', () => {
config()
const token = process.env.GITHUB_TOKEN ?? ''
const repo = {
owner: process.env.GITHUB_OWNER ?? '',
repo: process.env.GITHUB_REPO ?? ''
}
// it('reviewComments', async () => {

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Some tests seem to be commented

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Some tests seem to be commented

// const octokit = github.getOctokit(token)
// const comments = await octokit.rest.pulls.listReviewComments({
// pull_number: 367,
// ...github.context.repo
// })
// debug(comments)
// })

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
repo: repo

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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 / TypeScript Tests

Test has no assertions

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
repo: repo

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
})
debug(await githubMR.getReviews())
})

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
repo: repo

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
})
debug(await githubMR.getReviewComments())
})
})
17 changes: 0 additions & 17 deletions __tests__/index.test.ts

This file was deleted.

106 changes: 20 additions & 86 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,23 @@
/**
* Unit tests for the action's main functionality, src/main.ts
*
* These should be run as if the action was called from a workflow.
* Specifically, the inputs listed in `action.yml` should be set as environment
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

import * as core from '@actions/core'
import * as main from '../src/main'

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/

// Mock the GitHub Actions core library
let debugMock: jest.SpiedFunction<typeof core.debug>
let errorMock: jest.SpiedFunction<typeof core.error>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()

debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})

it('sets the time output', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return '500'
default:
return ''
import { config } from 'dotenv'

import { generateReport } from '../src/main'

describe('main.ts', () => {
config()
const token = process.env.GITHUB_TOKEN ?? ''

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

Check warning on line 9 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions

Check warning on line 9 in __tests__/main.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions
const args = {
sonarURL: 'https://sonar.openbsl.ru',
sonarProjectKey: 'yaxunit',
sonarBranchPlugin: true,
mergeID: 367,
githubToken: token,
repo: {
owner: 'alkoleft',
repo: 'yaxunit'
}
})

await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
expect(debugMock).toHaveBeenNthCalledWith(
2,
expect.stringMatching(timeRegex)
)
expect(debugMock).toHaveBeenNthCalledWith(
3,
expect.stringMatching(timeRegex)
)
expect(setOutputMock).toHaveBeenNthCalledWith(
1,
'time',
expect.stringMatching(timeRegex)
)
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
'milliseconds not a number'
)
expect(errorMock).not.toHaveBeenCalled()
}
generateReport(args)
})
})
85 changes: 85 additions & 0 deletions __tests__/publisher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { config } from 'dotenv'

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

describe('main.ts', () => {
config()
const token = process.env.GITHUB_TOKEN ?? ''
const repo = {
owner: process.env.GITHUB_OWNER ?? '',
repo: process.env.GITHUB_REPO ?? ''
}

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

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions
const sonar = new Sonar({
host: 'https://sonar.openbsl.ru',
projectKey: 'yaxunit',
branchPluginEnabled: true,
pull_number: 370
})
const github = new GithubMerge({
repo: repo,

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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 / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
})
const publisher = new Publisher(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 / TypeScript Tests

Test has no assertions

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Test has no assertions
const sonar = new Sonar({
host: 'https://sonar.openbsl.ru',
projectKey: 'yaxunit',
branchPluginEnabled: true,
pull_number: 370
})
const github = new GithubMerge({
repo: repo,

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

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 / TypeScript Tests

Expected property shorthand

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
})
const publisher = new Publisher(sonar, github)
const status = {
projectStatus: {
status: 'UNKNOWN',
ignoredConditions: false,
conditions: []
}
}
publisher.publishIssues(status, [
newIssue(
'1',
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
3
),
newIssue(
'2',
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
140
)
])
})
})

function newIssue(key: string, path: string, line: number) {
return {
key: key,
project: 'yaxunit',
component: 'yaxunit:' + path,
rule: 'bsl-language-server:Typo',
status: 'OPEN',
message: 'Возможная опечатка в "Обнуружена"',
severity: 'INFO',
line: line,
textRange: {
startLine: line,
endLine: line,
startOffset: 1,
endOffset: 1
},
effort: '1min',
tags: [],
type: 'CODE_SMELL'
}
}
24 changes: 24 additions & 0 deletions __tests__/sonar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { debug } from 'console'
import { config } from 'dotenv'

import { Sonar } from '../src/sonar'

describe('sonar', () => {
config()
const token = process.env.GITHUB_TOKEN ?? ''
const sonar = new Sonar({
host: 'https://sonar.openbsl.ru',
projectKey: 'yaxunit',
tokenKey: '',
branchPluginEnabled: true,
pull_number: 367
})

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

Check warning on line 17 in __tests__/sonar.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
debug(await sonar.getQualityStatus())
})

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

Check warning on line 21 in __tests__/sonar.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Test has no assertions
debug(await sonar.allIssues())
})
})
25 changes: 0 additions & 25 deletions __tests__/wait.test.ts

This file was deleted.

29 changes: 23 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'The name of your action here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'Sonar reviewer'
description: 'Publish sonar issues'
author: 'alkoleft'

# Add your action's branding here. This will appear on the GitHub Marketplace.
branding:
Expand All @@ -9,10 +9,27 @@ branding:

# Define your inputs here.
inputs:
milliseconds:
description: 'Your input description here'
sonar_url:
description: 'Sonar server'
required: true
default: '1000'
sonar_token:
description: 'Sonar token'
required: true
sonar_project:
description: 'Sonar project name'
required: true
sonar_branch_plugin:
description:
"Enable SonarQube Community-Branch-Plugin support. Please make sure, that
you've properly installed the plugin in SonarQube:
https://github.com/mc1arke/sonarqube-community-branch-plugin"
required: false
default: false
pull_number:
description: 'Pull request number'
required: false
github_token:
required: false

# Define your outputs here.
outputs:
Expand Down
Loading

0 comments on commit 7540b9b

Please sign in to comment.