Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Automated pull request checks #1159

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8441813
Feature/hozlucas28 automated checks (#1)
hozlucas28 Jan 22, 2024
b69cbfc
Feature/hozlucas28-automated-checks
hozlucas28 Jan 22, 2024
843f056
Merge branch 'mouredev:main' into main
hozlucas28 Jan 22, 2024
e7176ad
feature/hozlucas28-automated-checks
hozlucas28 Jan 22, 2024
da7f816
Fix GitHub Action - Check pull request
hozlucas28 Jan 22, 2024
5c499bb
Fix errors
hozlucas28 Jan 22, 2024
523eeee
Fix error message
hozlucas28 Jan 22, 2024
0442447
Remove trash
hozlucas28 Jan 22, 2024
cd2d23a
Fix challenge folder matching in getChallengeFolder function
hozlucas28 Jan 22, 2024
7bfb8c0
Temporal change
hozlucas28 Jan 22, 2024
17f343d
Temporal change
hozlucas28 Jan 22, 2024
aa89ab5
Remove temporal changes
hozlucas28 Jan 22, 2024
e5c80af
Update author input
hozlucas28 Jan 22, 2024
3f42243
Fix and improve getProgrammingLanguageExtension function
hozlucas28 Jan 22, 2024
2eda980
Set exact dependencies version
hozlucas28 Jan 23, 2024
b27eaf1
Update types of pull request trigger event
hozlucas28 Jan 23, 2024
a0a3217
Fix spam action on check boxes of pull request description
hozlucas28 Jan 23, 2024
8e4a466
Merge branch 'mouredev:main' into main
hozlucas28 Jan 23, 2024
cbe96bc
Update conditionals
hozlucas28 Jan 23, 2024
fece354
Add log
hozlucas28 Jan 23, 2024
68eca53
Update conditionals
hozlucas28 Jan 23, 2024
cf79f7d
Remove conditionals
hozlucas28 Jan 23, 2024
b6f1289
Add dependency to check-committed-files job
hozlucas28 Jan 23, 2024
630bf81
Remove dependency of check-committed-file job
hozlucas28 Jan 23, 2024
ac49e71
Update workflow
hozlucas28 Jan 23, 2024
4ff9f9c
Fix split
hozlucas28 Jan 23, 2024
eb0df49
Update pull_request_template.md
hozlucas28 Jan 23, 2024
cbe6941
Create utils.mjs
hozlucas28 Jan 24, 2024
e079ece
Create pull request actions
hozlucas28 Jan 24, 2024
9248308
Create workflow to check pull requests
hozlucas28 Jan 24, 2024
120ec06
Update template to avoid unnecessary workflow initialization and fix …
hozlucas28 Jan 24, 2024
e337de6
Merge branch 'main' into feature/hozlucas28-automated-pull-request-ch…
hozlucas28 Jan 24, 2024
a8db817
Feature/hozlucas28 automated pull request checks (#18)
hozlucas28 Jan 24, 2024
f323ce3
Merge pull request #22 from hozlucas28/feature/hozlucas28-automated-p…
hozlucas28 Jan 24, 2024
275d6a5
Create utils.mjs
hozlucas28 Jan 24, 2024
cde899c
Create pull request actions
hozlucas28 Jan 24, 2024
bd875a2
Create workflow to check pull requests
hozlucas28 Jan 24, 2024
9aa987f
Update template to avoid unnecessary workflow initialization and fix …
hozlucas28 Jan 24, 2024
502cc17
Merge branch 'main' into feature/hozlucas28-automated-pull-request-ch…
hozlucas28 Jan 24, 2024
39e0574
Remove "check-title" job for be non-essential
hozlucas28 Jan 25, 2024
f33a00c
Remove "check-committed-file" job in order to accept several corrections
hozlucas28 Jan 25, 2024
d1c3605
Update "check-committed-files" job in order to compare the file name …
hozlucas28 Jan 25, 2024
e3e336b
Add file extension check
hozlucas28 Jan 25, 2024
26da343
Fix programming language folder names seek
hozlucas28 Jan 25, 2024
fb6381c
Improve references
hozlucas28 Jan 25, 2024
b4b3bca
Add programming language folder name lowercase check
hozlucas28 Jan 26, 2024
1cce921
Merge branch 'feature/hozlucas28-automated-pull-request-checks' of ht…
hozlucas28 Jan 26, 2024
e049e1b
Add author input to action metadata
hozlucas28 Jan 26, 2024
a1d76b1
Merge branch 'main' into feature/hozlucas28-automated-pull-request-ch…
hozlucas28 Jan 26, 2024
df609f7
Revert "Merge branch 'main' into feature/hozlucas28-automated-pull-re…
hozlucas28 Jan 26, 2024
ffeca73
Create build of "check-committed-files" action
hozlucas28 Jan 26, 2024
5953f6f
Fix dependency bug
hozlucas28 Jan 26, 2024
dd52563
Update action reference
hozlucas28 Jan 26, 2024
c4a9c5b
Fix typographical errors
hozlucas28 Jan 26, 2024
322b574
Fix typographical error
hozlucas28 Jan 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ---------------------------------------------------------------------------- #
# NODE #
# ---------------------------------------------------------------------------- #

# ------------------------------- Dependencies ------------------------------- #

node_modules/
16 changes: 16 additions & 0 deletions .github/actions/pull-requests/check-committed-files/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
author: 'hozlucas28'

name: 'Check committed files'
description: 'Check if committed files of a pull request are valid'

runs:
using: 'node20'
main: 'dist/index.js'

inputs:
author:
description: 'Name of the user who created the pull request'
required: true
committed-files:
description: 'Committed files of the pull request'
required: true

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions .github/actions/pull-requests/check-committed-files/dist/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
@actions/core
MIT
The MIT License (MIT)

Copyright 2019 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@actions/http-client
MIT
Actions Http Client for Node.js

Copyright (c) GitHub, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


@fastify/busboy
MIT
Copyright Brian White. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

tunnel
MIT
The MIT License (MIT)

Copyright (c) 2012 Koichi Kobayashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


undici
MIT
MIT License

Copyright (c) Matteo Collina and Undici contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


uuid
MIT
The MIT License (MIT)

Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
80 changes: 80 additions & 0 deletions .github/actions/pull-requests/check-committed-files/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { debug, getInput, setFailed } from '@actions/core'
import path from 'node:path'
import {
arraytoString,
getProgrammingLanguageExtension,
getProgrammingLanguageFolderName,
getProgrammingLanguageFolderNames,
} from '../../utils.mjs'

// Inputs
const author = getInput('author')
const committedFiles = getInput('committed-files').split('\\n')
debug(`'author' (input): ${author}`)
debug(`'committed-files' (input): ${committedFiles}`)

// Required data
const authorLowerCase = author.toLowerCase()
const programmingLanguageFolders = getProgrammingLanguageFolderNames()
debug(`Author name (lowercase): ${authorLowerCase}`)
debug(`Programming language folder names: ${programmingLanguageFolders}`)

// Check each commited file
for (const committedFile of committedFiles) {
const parsedFile = path.parse(committedFile)
debug(`Committed file properties: ${parsedFile}`)

// Check file name
const isValidFileName = parsedFile.name.toLowerCase() === authorLowerCase
debug(`Is valid file name? ${isValidFileName}`)

if (!isValidFileName) {
setFailed(
`The file name: '${parsedFile.base}', inside '${parsedFile.dir}' directory doesn't match with the author name of the pull request. ` +
'Please rename the file name. ' +
`It should be: '${author}', case insensitive. ` +
'If you think this is an error, please contact an administrator.'
)
}

// Check programming language folder
const programmingLanguageFolder = parsedFile.dir.split(path.sep).pop() // Get the last folder, in this case the programming language name.
debug(`Last folder of the commited file: ${programmingLanguageFolder}`)

if (!programmingLanguageFolder) {
throw new Error(
`The programming language folder of '${parsedFile.base}' (committed file) inside '${parsedFile.dir}' is undefined!`
)
}

if (!programmingLanguageFolders.includes(programmingLanguageFolder)) {
setFailed(
`The programming language folder '${programmingLanguageFolder}', where '${parsedFile.base}' (committed file) is located doesn't match with an existing one. ` +
`It should be on of these: ${arraytoString({
array: programmingLanguageFolders,
finalSeparator: ', or ',
separator: ', ',
})}. ` +
'If you think this is an error, please contact an administrator.'
)
}

// Check file extension
const expectedFileExtBasedOnLastFolder = getProgrammingLanguageExtension(programmingLanguageFolder)
const isValidFileExtension = parsedFile.ext === expectedFileExtBasedOnLastFolder
debug(`Expected file extension based on the last folder of the commited file: ${expectedFileExtBasedOnLastFolder}`)
debug(`Is valid file extension? ${isValidFileExtension}`)

if (!isValidFileExtension) {
const expectedLastFolderBasedOnCommittedFileExt = getProgrammingLanguageFolderName(parsedFile.ext)
debug(`Expected last folder based on the extension of the commited file: ${expectedLastFolderBasedOnCommittedFileExt}`)

setFailed(
`The file extension of '${parsedFile.base}' file, inside '${parsedFile.dir}' directory doesn't match with the programming language folder. ` +
'Check the file extension or the programming language folder where it is located. ' +
`The file extension should be: '${expectedFileExtBasedOnLastFolder}', ` +
`or the programming language folder where it is located should be: '${expectedLastFolderBasedOnCommittedFileExt}'. ` +
'If you think this is an error, please contact an administrator.'
)
}
}

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

19 changes: 19 additions & 0 deletions .github/actions/pull-requests/check-committed-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"author": "hozlucas28",
"dependencies": {
"@actions/core": "1.10.1"
},
"description": "GitHub Action to check committed files of a pull request",
"devDependencies": {
"@vercel/ncc": "^0.38.1"
},
"keywords": [],
"license": "MIT",
"main": "dist/index.js",
"name": "check-committed-files",
"scripts": {
"build": "ncc build main.js --minify --target es2022 --license licenses.txt"
},
"type": "module",
"version": "1.0.0"
}
Loading