mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-26 08:01:03 -05:00
Remove duplicated code (#1137)
* Remove duplicated code on ghe config apply * Add funciton to replace duplicated cod * Fix comment * Fix java test duplicated code * Fix python test duplicated code * Update javascript es test acording to change * Fix linters bash * Fix javascript standard linters on javascript es good
This commit is contained in:
parent
594be7e0b2
commit
5c31b85619
10 changed files with 190 additions and 390 deletions
|
@ -31,6 +31,22 @@ Header() {
|
||||||
info "-------------------------------------------------------"
|
info "-------------------------------------------------------"
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
|
#### Function CheckShellErrors #################################################
|
||||||
|
CheckShellErrors() {
|
||||||
|
#######################
|
||||||
|
# Load the error code #
|
||||||
|
#######################
|
||||||
|
ERROR_CODE=$?
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ $ERROR_CODE -ne 0 ]; then
|
||||||
|
error "$1"
|
||||||
|
fatal "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
#### Function CleanTestFiles ###################################################
|
#### Function CleanTestFiles ###################################################
|
||||||
CleanTestFiles() {
|
CleanTestFiles() {
|
||||||
info "-------------------------------------------------------"
|
info "-------------------------------------------------------"
|
||||||
|
@ -44,18 +60,7 @@ CleanTestFiles() {
|
||||||
find "${GITHUB_WORKSPACE}" -type f -name "*_bad_*" -o -path "*javascript_prettier*" -name "*javascript_good*" 2>&1
|
find "${GITHUB_WORKSPACE}" -type f -name "*_bad_*" -o -path "*javascript_prettier*" -name "*javascript_good*" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to get list of all files!" "ERROR:[${FIND_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to get list of all files!"
|
|
||||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Get the directory and validate it came from tests folder #
|
# Get the directory and validate it came from tests folder #
|
||||||
|
@ -78,18 +83,7 @@ CleanTestFiles() {
|
||||||
rm -f "$FILE" 2>&1
|
rm -f "$FILE" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to remove file:[${FILE}]!"
|
|
||||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -107,18 +101,7 @@ CleanTestDockerFiles() {
|
||||||
find "${GITHUB_WORKSPACE}" -type f -name "*Dockerfile" 2>&1
|
find "${GITHUB_WORKSPACE}" -type f -name "*Dockerfile" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to get list of all file for Docker!" "ERROR:[${FIND_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to get list of all file for Docker!"
|
|
||||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Get the directory and validate it came from tests folder #
|
# Get the directory and validate it came from tests folder #
|
||||||
|
@ -141,18 +124,7 @@ CleanTestDockerFiles() {
|
||||||
rm -f "$FILE" 2>&1
|
rm -f "$FILE" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to remove file:[${FILE}]!"
|
|
||||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -170,19 +142,7 @@ CleanSHAFolder() {
|
||||||
sudo rm -rf "${GITHUB_SHA}" 2>&1
|
sudo rm -rf "${GITHUB_SHA}" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! Failed to remove folder:[${GITHUB_SHA}]!" "ERROR:[${REMOVE_CMD}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
# Error
|
|
||||||
error "ERROR! Failed to remove folder:[${GITHUB_SHA}]!"
|
|
||||||
fatal "ERROR:[${REMOVE_CMD}]"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
#### Function RenameTestFolder #################################################
|
#### Function RenameTestFolder #################################################
|
||||||
|
@ -198,18 +158,7 @@ RenameTestFolder() {
|
||||||
mv "${TEST_FOLDER}" "${CLEAN_FOLDER}" 2>&1
|
mv "${TEST_FOLDER}" "${CLEAN_FOLDER}" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to move test folder!" "ERROR:[${RENAME_FOLDER_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to move test folder!"
|
|
||||||
fatal "ERROR:[${RENAME_FOLDER_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
################################################################################
|
################################################################################
|
||||||
#### Function CleanPowershell ##################################################
|
#### Function CleanPowershell ##################################################
|
||||||
|
@ -228,18 +177,7 @@ CleanPowershell() {
|
||||||
find "${GITHUB_WORKSPACE}" -type f -name "*.psd1" 2>&1
|
find "${GITHUB_WORKSPACE}" -type f -name "*.psd1" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to get list of all file for *.psd1!" "ERROR:[${FIND_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to get list of all file for *.psd1!"
|
|
||||||
fatal "ERROR:[${FIND_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Get the directory and validate it came from tests folder #
|
# Get the directory and validate it came from tests folder #
|
||||||
|
@ -262,18 +200,7 @@ CleanPowershell() {
|
||||||
rm -f "$FILE" 2>&1
|
rm -f "$FILE" 2>&1
|
||||||
)
|
)
|
||||||
|
|
||||||
#######################
|
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||||
# Load the error code #
|
|
||||||
#######################
|
|
||||||
ERROR_CODE=$?
|
|
||||||
|
|
||||||
##############################
|
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ $ERROR_CODE -ne 0 ]; then
|
|
||||||
error "ERROR! failed to remove file:[${FILE}]!"
|
|
||||||
fatal "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,33 @@ PROCESS_CHECK=0 # Count of times to check the process
|
||||||
########################### SUB ROUTINES BELOW #################################
|
########################### SUB ROUTINES BELOW #################################
|
||||||
################################################################################
|
################################################################################
|
||||||
################################################################################
|
################################################################################
|
||||||
|
#### Function CheckShellErrors #################################################
|
||||||
|
CheckShellErrors() {
|
||||||
|
COUNTER=$1
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ "${ERROR_CODE}" -ne 0 ]; then
|
||||||
|
error "Failed to sleep!"
|
||||||
|
error "[${SLEEP_CMD}]"
|
||||||
|
info "Will try to call apply as last effort..."
|
||||||
|
####################################
|
||||||
|
# Call config apply as last effort #
|
||||||
|
####################################
|
||||||
|
RunConfigApply
|
||||||
|
else
|
||||||
|
#####################
|
||||||
|
# Increment counter #
|
||||||
|
#####################
|
||||||
|
((COUNTER++))
|
||||||
|
##########################################
|
||||||
|
# Try to check for the pid/process again #
|
||||||
|
##########################################
|
||||||
|
$2
|
||||||
|
fi
|
||||||
|
return "$COUNTER"
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
#### Function CheckGHEPid ######################################################
|
#### Function CheckGHEPid ######################################################
|
||||||
CheckGHEPid() {
|
CheckGHEPid() {
|
||||||
##################################
|
##################################
|
||||||
|
@ -48,27 +75,7 @@ CheckGHEPid() {
|
||||||
#######################
|
#######################
|
||||||
ERROR_CODE=$?
|
ERROR_CODE=$?
|
||||||
|
|
||||||
##############################
|
PID_CHECK=CheckShellErrors "PID_CHECK" "CheckGHEPid"
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
|
||||||
error "Failed to sleep!"
|
|
||||||
error "[${SLEEP_CMD}]"
|
|
||||||
info "Will try to call apply as last effort..."
|
|
||||||
####################################
|
|
||||||
# Call config apply as last effort #
|
|
||||||
####################################
|
|
||||||
RunConfigApply
|
|
||||||
else
|
|
||||||
#####################
|
|
||||||
# Increment counter #
|
|
||||||
#####################
|
|
||||||
((PID_CHECK++))
|
|
||||||
##################################
|
|
||||||
# Try to check for the pid again #
|
|
||||||
##################################
|
|
||||||
CheckGHEPid
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -111,27 +118,7 @@ CheckGHEProcess() {
|
||||||
#######################
|
#######################
|
||||||
ERROR_CODE=$?
|
ERROR_CODE=$?
|
||||||
|
|
||||||
##############################
|
PROCESS_CHECK=CheckShellErrors "PROCESS_CHECK" "CheckGHEProcess"
|
||||||
# Check the shell for errors #
|
|
||||||
##############################
|
|
||||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
|
||||||
error "Failed to sleep!"
|
|
||||||
error "[${SLEEP_CMD}]"
|
|
||||||
info "Will try to call apply as last effort..."
|
|
||||||
####################################
|
|
||||||
# Call config apply as last effort #
|
|
||||||
####################################
|
|
||||||
RunConfigApply
|
|
||||||
else
|
|
||||||
#####################
|
|
||||||
# Increment counter #
|
|
||||||
#####################
|
|
||||||
((PROCESS_CHECK++))
|
|
||||||
######################################
|
|
||||||
# Try to check for the process again #
|
|
||||||
######################################
|
|
||||||
CheckGHEProcess
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
var createHandler = require( 'github-webhook-handler')
|
var createHandler = require('github-webhook-handler')
|
||||||
|
|
||||||
var handler = createHandler( { path : /webhook, secret : (process.env.SECRET) })
|
var handler = createHandler({
|
||||||
|
path: /webhook, secret : (process.env.SECRET) })
|
||||||
|
|
||||||
var userArray = [ 'user1' ]
|
var userArray = ['user1']
|
||||||
here is some garbage = that
|
here is some garbage = that
|
||||||
|
|
||||||
var teamDescription = Team of Robots
|
var teamDescription = Team of Robots
|
||||||
|
@ -18,19 +19,19 @@ var orgRepos = []
|
||||||
// var creator = ""
|
// var creator = ""
|
||||||
|
|
||||||
var foo = someFunction();
|
var foo = someFunction();
|
||||||
var bar = a + 1;
|
var bar = a + 1;
|
||||||
|
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
handler(req, res, function (err) {
|
handler(req, res, function (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
res.end('no such location')
|
res.end('no such location')
|
||||||
})
|
})
|
||||||
}).listen(3000)
|
}).listen(3000)
|
||||||
|
|
||||||
handler.on('error', function (err) {
|
handler.on('error', function (err) {
|
||||||
console.await.error('Error:', err.message)
|
console.await.error('Error:', err.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
handler.on('repository', function (event) {
|
handler.on('repository', function (event) {
|
||||||
if (event.payload.action === 'created') {
|
if (event.payload.action === 'created') {
|
||||||
|
@ -40,10 +41,10 @@ handler.on('repository', function (event) {
|
||||||
getTeamID(org)
|
getTeamID(org)
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
handler.on('team', function (event) {
|
handler.on('team', function (event) {
|
||||||
// TODO user events such as being removed from team or org
|
// TODO user events such as being removed from team or org
|
||||||
if (event.payload.action === 'deleted') {
|
if (event.payload.action === 'deleted') {
|
||||||
// const name = event.payload.team.name
|
// const name = event.payload.team.name
|
||||||
const org = event.payload.organization.login
|
const org = event.payload.organization.login
|
||||||
|
@ -55,9 +56,9 @@ handler.on('team', function (event) {
|
||||||
// const repo = event.payload.repository.full_name
|
// const repo = event.payload.repository.full_name
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function getTeamID (org) {
|
function getTeamID(org) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -70,34 +71,21 @@ function getTeamID (org) {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
if (item.name === teamName) {
|
|
||||||
teamId = item.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error, (error) => {
|
req.on('error, (error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkTeamIDVariable (repo) {
|
function checkTeamIDVariable(repo) {
|
||||||
if (typeof teamId != 'undefined') {
|
if (typeof teamId != 'undefined') {
|
||||||
addTeamToRepo(repo, teamId)
|
addTeamToRepo(repo, teamId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkReposVariable (org) {
|
function checkReposVariable(org) {
|
||||||
if (typeof orgRepos !== 'undefined') {
|
if (typeof orgRepos !== 'undefined') {
|
||||||
// for(var repo of orgRepos) {
|
// for(var repo of orgRepos) {
|
||||||
// addTeamToRepo(repo, teamId)
|
// addTeamToRepo(repo, teamId)
|
||||||
|
@ -106,7 +94,7 @@ function checkReposVariable (org) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTeamToRepo (repo, teamId) {
|
function addTeamToRepo(repo, teamId) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
permission: teamAccess
|
permission: teamAccess
|
||||||
|
@ -146,7 +134,7 @@ function addTeamToRepo (repo, teamId) {
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function reCreateTeam (org) {
|
function reCreateTeam(org) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
name: teamName,
|
name: teamName,
|
||||||
|
@ -188,7 +176,7 @@ function reCreateTeam (org) {
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRepositories (org) {
|
function getRepositories(org) {
|
||||||
orgRepos = []
|
orgRepos = []
|
||||||
|
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
|
@ -203,20 +191,6 @@ function getRepositories (org) {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
orgRepos.push(item.full_name)
|
|
||||||
|
|
||||||
console.log(item.full_name)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
req.on('error', (error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
var http = require('http')
|
const http = require('http')
|
||||||
var createHandler = require('github-webhook-handler')
|
const createHandler = require('github-webhook-handler')
|
||||||
var handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) })
|
const handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) })
|
||||||
|
|
||||||
var userArray = ['user1']
|
const userArray = ['user1']
|
||||||
|
|
||||||
var teamDescription = 'Team of Robots'
|
const teamDescription = 'Team of Robots'
|
||||||
var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
|
const teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
|
||||||
|
|
||||||
var teamName = process.env.GHES_TEAM_NAME
|
const teamName = process.env.GHES_TEAM_NAME
|
||||||
var teamAccess = 'pull' // pull,push,admin options here
|
const teamAccess = 'pull' // pull,push,admin options here
|
||||||
var teamId = ''
|
const teamId = ''
|
||||||
|
|
||||||
var orgRepos = []
|
|
||||||
|
|
||||||
// var creator = ""
|
// var creator = ""
|
||||||
|
|
||||||
|
@ -31,61 +29,21 @@ handler.on('repository', function (event) {
|
||||||
if (event.payload.action === 'created') {
|
if (event.payload.action === 'created') {
|
||||||
const repo = event.payload.repository.full_name
|
const repo = event.payload.repository.full_name
|
||||||
console.log(repo)
|
console.log(repo)
|
||||||
const org = event.payload.repository.owner.login
|
|
||||||
getTeamID(org)
|
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
handler.on('team', function (event) {
|
handler.on('team', function (event) {
|
||||||
// TODO user events such as being removed from team or org
|
// TODO user events such as being removed from team or org
|
||||||
if (event.payload.action === 'deleted') {
|
if (event.payload.action === 'deleted') {
|
||||||
// const name = event.payload.team.name
|
// const name = event.payload.team.name
|
||||||
const org = event.payload.organization.login
|
|
||||||
getRepositories(org)
|
|
||||||
setTimeout(checkReposVariable, 5000)
|
setTimeout(checkReposVariable, 5000)
|
||||||
} else if (event.payload.action === 'removed_from_repository') {
|
} else if (event.payload.action === 'removed_from_repository') {
|
||||||
const org = event.payload.organization.login
|
|
||||||
getTeamID(org)
|
|
||||||
// const repo = event.payload.repository.full_name
|
// const repo = event.payload.repository.full_name
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function getTeamID (org) {
|
|
||||||
const https = require('https')
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
hostname: (process.env.GHE_HOST),
|
|
||||||
port: 443,
|
|
||||||
path: '/api/v3/orgs/' + org + '/teams',
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
Authorization: 'token ' + (process.env.GHE_TOKEN),
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
if (item.name === teamName) {
|
|
||||||
teamId = item.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
|
||||||
|
|
||||||
req.end()
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkTeamIDVariable (repo) {
|
function checkTeamIDVariable (repo) {
|
||||||
if (typeof teamId !== 'undefined') {
|
if (typeof teamId !== 'undefined') {
|
||||||
addTeamToRepo(repo, teamId)
|
addTeamToRepo(repo, teamId)
|
||||||
|
@ -143,8 +101,7 @@ function reCreateTeam (org) {
|
||||||
name: teamName,
|
name: teamName,
|
||||||
description: teamDescription,
|
description: teamDescription,
|
||||||
privacy: teamPrivacy,
|
privacy: teamPrivacy,
|
||||||
maintainers: userArray,
|
maintainers: userArray
|
||||||
repo_names: orgRepos
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -178,38 +135,3 @@ function reCreateTeam (org) {
|
||||||
req.write(data)
|
req.write(data)
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRepositories (org) {
|
|
||||||
orgRepos = []
|
|
||||||
|
|
||||||
const https = require('https')
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
hostname: (process.env.GHE_HOST),
|
|
||||||
port: 443,
|
|
||||||
path: '/api/v3/orgs/' + org + '/repos',
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
Authorization: 'token ' + (process.env.GHE_TOKEN),
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
orgRepos.push(item.full_name)
|
|
||||||
console.log(item.full_name)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
|
||||||
console.error(error)
|
|
||||||
})
|
|
||||||
|
|
||||||
req.end()
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,6 +2,6 @@ TAP version 13
|
||||||
1..2
|
1..2
|
||||||
not ok 1 - javascript_bad_1.js
|
not ok 1 - javascript_bad_1.js
|
||||||
---
|
---
|
||||||
message: \n/tmp/lint/.automation/test/javascript_es/javascript_bad_1.js\n 4 39 error Parsing error Unterminated regular expression literal\n\n✖ 1 problem (1 error, 0 warnings)\n
|
message: \n/tmp/lint/.automation/test/javascript_es/javascript_bad_1.js\n 5 9 error Parsing error Unterminated regular expression literal\n\n✖ 1 problem (1 error, 0 warnings)\n
|
||||||
...
|
...
|
||||||
ok 2 - javascript_good_1.js
|
ok 2 - javascript_good_1.js
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
var createHandler = require( 'github-webhook-handler')
|
var createHandler = require('github-webhook-handler')
|
||||||
|
|
||||||
var handler = createHandler( { path : /webhook, secret : (process.env.SECRET) })
|
var handler = createHandler({
|
||||||
|
path: /webhook, secret : (process.env.SECRET) })
|
||||||
|
|
||||||
var userArray = [ 'user1' ]
|
var userArray = ['user1']
|
||||||
here is some garbage = that
|
here is some garbage = that
|
||||||
|
|
||||||
var teamDescription = Team of Robots
|
var teamDescription = Team of Robots
|
||||||
|
@ -18,19 +19,19 @@ var orgRepos = []
|
||||||
// var creator = ""
|
// var creator = ""
|
||||||
|
|
||||||
var foo = someFunction();
|
var foo = someFunction();
|
||||||
var bar = a + 1;
|
var bar = a + 1;
|
||||||
|
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
handler(req, res, function (err) {
|
handler(req, res, function (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
res.end('no such location')
|
res.end('no such location')
|
||||||
})
|
})
|
||||||
}).listen(3000)
|
}).listen(3000)
|
||||||
|
|
||||||
handler.on('error', function (err) {
|
handler.on('error', function (err) {
|
||||||
console.await.error('Error:', err.message)
|
console.await.error('Error:', err.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
handler.on('repository', function (event) {
|
handler.on('repository', function (event) {
|
||||||
if (event.payload.action === 'created') {
|
if (event.payload.action === 'created') {
|
||||||
|
@ -40,10 +41,10 @@ handler.on('repository', function (event) {
|
||||||
getTeamID(org)
|
getTeamID(org)
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
handler.on('team', function (event) {
|
handler.on('team', function (event) {
|
||||||
// TODO user events such as being removed from team or org
|
// TODO user events such as being removed from team or org
|
||||||
if (event.payload.action === 'deleted') {
|
if (event.payload.action === 'deleted') {
|
||||||
// const name = event.payload.team.name
|
// const name = event.payload.team.name
|
||||||
const org = event.payload.organization.login
|
const org = event.payload.organization.login
|
||||||
|
@ -55,9 +56,9 @@ handler.on('team', function (event) {
|
||||||
// const repo = event.payload.repository.full_name
|
// const repo = event.payload.repository.full_name
|
||||||
setTimeout(checkTeamIDVariable, 1000)
|
setTimeout(checkTeamIDVariable, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function getTeamID (org) {
|
function getTeamID(org) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -70,34 +71,21 @@ function getTeamID (org) {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
if (item.name === teamName) {
|
|
||||||
teamId = item.id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error, (error) => {
|
req.on('error, (error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkTeamIDVariable (repo) {
|
function checkTeamIDVariable(repo) {
|
||||||
if (typeof teamId != 'undefined') {
|
if (typeof teamId != 'undefined') {
|
||||||
addTeamToRepo(repo, teamId)
|
addTeamToRepo(repo, teamId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkReposVariable (org) {
|
function checkReposVariable(org) {
|
||||||
if (typeof orgRepos !== 'undefined') {
|
if (typeof orgRepos !== 'undefined') {
|
||||||
// for(var repo of orgRepos) {
|
// for(var repo of orgRepos) {
|
||||||
// addTeamToRepo(repo, teamId)
|
// addTeamToRepo(repo, teamId)
|
||||||
|
@ -106,7 +94,7 @@ function checkReposVariable (org) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTeamToRepo (repo, teamId) {
|
function addTeamToRepo(repo, teamId) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
permission: teamAccess
|
permission: teamAccess
|
||||||
|
@ -146,7 +134,7 @@ function addTeamToRepo (repo, teamId) {
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function reCreateTeam (org) {
|
function reCreateTeam(org) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const data = JSON.stringify({
|
const data = JSON.stringify({
|
||||||
name: teamName,
|
name: teamName,
|
||||||
|
@ -188,7 +176,7 @@ function reCreateTeam (org) {
|
||||||
req.end()
|
req.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRepositories (org) {
|
function getRepositories(org) {
|
||||||
orgRepos = []
|
orgRepos = []
|
||||||
|
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
|
@ -203,20 +191,6 @@ function getRepositories (org) {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let body = []
|
|
||||||
const req = https.request(options, (res) => {
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
body.push(chunk)
|
|
||||||
|
|
||||||
}).on('end', () => {
|
|
||||||
body = JSON.parse(Buffer.concat(body))
|
|
||||||
body.forEach(item => {
|
|
||||||
orgRepos.push(item.full_name)
|
|
||||||
|
|
||||||
console.log(item.full_name)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
req.on('error', (error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
|
@ -26,6 +26,12 @@ headers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def make_request(query, query_variables):
|
||||||
|
payload = {"query": query, "variables": query_variables}
|
||||||
|
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def create_label(repo_id, label):
|
def create_label(repo_id, label):
|
||||||
"""
|
"""
|
||||||
Create label in the supplied repo.
|
Create label in the supplied repo.
|
||||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
|
||||||
print("Created label {label}".format(label=label["name"]))
|
print("Created label {label}".format(label=label["name"]))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables)
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
|
||||||
|
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
|
@ -26,6 +26,12 @@ headers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def make_request(query, query_variables):
|
||||||
|
payload = {"query": query, "variables": query_variables}
|
||||||
|
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def create_label(repo_id, label):
|
def create_label(repo_id, label):
|
||||||
"""
|
"""
|
||||||
Create label in the supplied repo.
|
Create label in the supplied repo.
|
||||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
|
||||||
print("Created label {label}".format(label=label["name"]))
|
print("Created label {label}".format(label=label["name"]))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
|
||||||
|
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
|
@ -26,6 +26,12 @@ headers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def make_request(query, query_variables):
|
||||||
|
payload = {"query": query, "variables": query_variables}
|
||||||
|
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def create_label(repo_id, label):
|
def create_label(repo_id, label):
|
||||||
"""
|
"""
|
||||||
Create label in the supplied repo.
|
Create label in the supplied repo.
|
||||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
|
||||||
print("Created label {label}".format(label=label["name"]))
|
print("Created label {label}".format(label=label["name"]))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
|
||||||
|
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
|
@ -26,6 +26,12 @@ headers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def make_request(query, query_variables):
|
||||||
|
payload = {"query": query, "variables": query_variables}
|
||||||
|
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def create_label(repo_id, label):
|
def create_label(repo_id, label):
|
||||||
"""
|
"""
|
||||||
Create label in the supplied repo.
|
Create label in the supplied repo.
|
||||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
|
||||||
print("Created label {label}".format(label=label["name"]))
|
print("Created label {label}".format(label=label["name"]))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
||||||
) as query_file:
|
) as query_file:
|
||||||
query = "".join(query_file.readlines())
|
query = "".join(query_file.readlines())
|
||||||
|
|
||||||
payload = {"query": query, "variables": query_variables}
|
response = make_request(query, query_variables).json()
|
||||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
|
||||||
|
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
Loading…
Reference in a new issue