Skip to content

Commit

Permalink
checkDocumentation now returns messages + first test on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FG-TUM committed Jan 22, 2024
1 parent 3c7d65e commit 1c85fd9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 67 deletions.
140 changes: 92 additions & 48 deletions dist/index.js

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

43 changes: 24 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { findFileByName } from './utils'
* @param changes - An array of paths to files that have been changed.
* @returns An exit code: 0 if no errors were found, 1 if errors were found.
*/
function checkDocumentation(userdocs: string[], changes: string[]): number {
// Flag for if any errors are found
let exitCode = 0
function checkDocumentation(userdocs: string[], changes: string[]): string {
let output= ''

Check failure on line 14 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `=·''·` with `·=·''`

const changesBasenames = changes.map(f => path.basename(f))

Expand All @@ -36,7 +35,6 @@ function checkDocumentation(userdocs: string[], changes: string[]): number {
// If the path in the tag doesn't exist, it's an error
if (findFileByName('.', tag) === null) {
unknownTags.push(tag)
exitCode = 1
} else {
fileTags = fileTags.concat(fs.readdirSync(tag))
}
Expand All @@ -46,26 +44,20 @@ function checkDocumentation(userdocs: string[], changes: string[]): number {
// If the path in the tag doesn't exist, it's an error
if (findFileByName('.', tag) === null) {
unknownTags.push(tag)
exitCode = 1
}
// If any tag appears in the changes, the doc file also has to be in the changes
if (!docfileHasChanges && changesBasenames.includes(tag)) {
console.log(
`${tag} has been changed, but ${docfile} is unchanged. Check that the documentation is still up to date!`
)
exitCode = 1
output += `${tag} has been changed, but ${docfile} is unchanged. Check that the documentation is still up to date!\n`
}
}

// If any unknownTags were found (unknownTags not empty)
if (unknownTags.length !== 0) {
console.log(
`In ${docfile}, the following tags do not exist:\n${unknownTags}`
)
output += `In ${docfile}, the following tags do not exist:\n${unknownTags}\n`
}
}

return exitCode
return output
}

/**
Expand All @@ -79,7 +71,7 @@ export async function run(): Promise<void> {
const dirs = core.getInput('userDocsDirs').split(/\s+/)
const ghToken = core.getInput('githubToken')
const [owner, repo] = (process.env.GITHUB_REPOSITORY ?? '').split('/')
const pull_number = parseInt(
const prNumber = parseInt(
(process.env.GITHUB_REF_NAME ?? '').split('/')[0],
10
)
Expand All @@ -100,19 +92,32 @@ export async function run(): Promise<void> {
const response = await octokit.rest.pulls.listFiles({
owner,
repo,
pull_number
prNumber
})
// Extract file names from the response
const changedFiles = response.data.map(file => file.filename)
core.info(`changed files: ${changedFiles}`)

/*const exitCode =*/ checkDocumentation(docFiles, changedFiles)
const errMsgs = checkDocumentation(docFiles, changedFiles)

// Set outputs for other workflow steps to use
// TODO: use exitCode
core.setOutput('warnings', 'NO WARNINGS')
if (errMsgs.length === 0) {
core.setOutput('warnings', 'NO WARNINGS')
} else {
core.setOutput('warnings', 'DOC MIGHT NEED UPDATE OR TAGS ARE INVALID')
// add a comment with the warnings to the PR
await octokit.rest.issues.createComment({
owner: owner,

Check failure on line 110 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
repo: repo,

Check failure on line 111 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand
issue_number: prNumber,
body: errMsgs
});

Check failure on line 114 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `;`

Check failure on line 114 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Extra semicolon
}

Check failure on line 115 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `⏎`

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

0 comments on commit 1c85fd9

Please sign in to comment.