mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-09 18:43:34 -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 "-------------------------------------------------------"
|
||||
}
|
||||
################################################################################
|
||||
#### 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 ###################################################
|
||||
CleanTestFiles() {
|
||||
info "-------------------------------------------------------"
|
||||
|
@ -44,18 +60,7 @@ CleanTestFiles() {
|
|||
find "${GITHUB_WORKSPACE}" -type f -name "*_bad_*" -o -path "*javascript_prettier*" -name "*javascript_good*" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to get list of all files!" "ERROR:[${FIND_CMD[*]}]"
|
||||
|
||||
############################################################
|
||||
# Get the directory and validate it came from tests folder #
|
||||
|
@ -78,18 +83,7 @@ CleanTestFiles() {
|
|||
rm -f "$FILE" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -107,18 +101,7 @@ CleanTestDockerFiles() {
|
|||
find "${GITHUB_WORKSPACE}" -type f -name "*Dockerfile" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to get list of all file for Docker!" "ERROR:[${FIND_CMD[*]}]"
|
||||
|
||||
############################################################
|
||||
# Get the directory and validate it came from tests folder #
|
||||
|
@ -141,18 +124,7 @@ CleanTestDockerFiles() {
|
|||
rm -f "$FILE" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -170,19 +142,7 @@ CleanSHAFolder() {
|
|||
sudo rm -rf "${GITHUB_SHA}" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! Failed to remove folder:[${GITHUB_SHA}]!" "ERROR:[${REMOVE_CMD}]"
|
||||
}
|
||||
################################################################################
|
||||
#### Function RenameTestFolder #################################################
|
||||
|
@ -198,18 +158,7 @@ RenameTestFolder() {
|
|||
mv "${TEST_FOLDER}" "${CLEAN_FOLDER}" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to move test folder!" "ERROR:[${RENAME_FOLDER_CMD[*]}]"
|
||||
}
|
||||
################################################################################
|
||||
#### Function CleanPowershell ##################################################
|
||||
|
@ -228,18 +177,7 @@ CleanPowershell() {
|
|||
find "${GITHUB_WORKSPACE}" -type f -name "*.psd1" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to get list of all file for *.psd1!" "ERROR:[${FIND_CMD[*]}]"
|
||||
|
||||
############################################################
|
||||
# Get the directory and validate it came from tests folder #
|
||||
|
@ -262,18 +200,7 @@ CleanPowershell() {
|
|||
rm -f "$FILE" 2>&1
|
||||
)
|
||||
|
||||
#######################
|
||||
# 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
|
||||
CheckShellErrors "ERROR! failed to remove file:[${FILE}]!" "ERROR:[${REMOVE_FILE_CMD[*]}]"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
|
|
@ -20,6 +20,33 @@ PROCESS_CHECK=0 # Count of times to check the process
|
|||
########################### 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 ######################################################
|
||||
CheckGHEPid() {
|
||||
##################################
|
||||
|
@ -48,27 +75,7 @@ CheckGHEPid() {
|
|||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# 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
|
||||
PID_CHECK=CheckShellErrors "PID_CHECK" "CheckGHEPid"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -111,27 +118,7 @@ CheckGHEProcess() {
|
|||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# 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
|
||||
PROCESS_CHECK=CheckShellErrors "PROCESS_CHECK" "CheckGHEProcess"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
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
|
||||
|
||||
var teamDescription = Team of Robots
|
||||
|
@ -18,46 +19,46 @@ var orgRepos = []
|
|||
// var creator = ""
|
||||
|
||||
var foo = someFunction();
|
||||
var bar = a + 1;
|
||||
var bar = a + 1;
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
handler(req, res, function (err) {
|
||||
console.log(err)
|
||||
res.statusCode = 404
|
||||
res.end('no such location')
|
||||
})
|
||||
}).listen(3000)
|
||||
http.createServer(function (req, res) {
|
||||
handler(req, res, function (err) {
|
||||
console.log(err)
|
||||
res.statusCode = 404
|
||||
res.end('no such location')
|
||||
})
|
||||
}).listen(3000)
|
||||
|
||||
handler.on('error', function (err) {
|
||||
console.await.error('Error:', err.message)
|
||||
})
|
||||
console.await.error('Error:', err.message)
|
||||
})
|
||||
|
||||
handler.on('repository', function (event) {
|
||||
if (event.payload.action === 'created') {
|
||||
const repo = event.payload.repository.full_name
|
||||
console.log(repo)
|
||||
const org = event.payload.repository.owner.login
|
||||
getTeamID(org)
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
if (event.payload.action === 'created') {
|
||||
const repo = event.payload.repository.full_name
|
||||
console.log(repo)
|
||||
const org = event.payload.repository.owner.login
|
||||
getTeamID(org)
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
handler.on('team', function (event) {
|
||||
// TODO user events such as being removed from team or org
|
||||
if (event.payload.action === 'deleted') {
|
||||
// const name = event.payload.team.name
|
||||
const org = event.payload.organization.login
|
||||
getRepositories(org)
|
||||
setTimeout(checkReposVariable, 5000)
|
||||
} else if (event.payload.action === 'removed_from_repository') {
|
||||
const org = event.payload.organization.login
|
||||
getTeamID(org)
|
||||
// const repo = event.payload.repository.full_name
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
// TODO user events such as being removed from team or org
|
||||
if (event.payload.action === 'deleted') {
|
||||
// const name = event.payload.team.name
|
||||
const org = event.payload.organization.login
|
||||
getRepositories(org)
|
||||
setTimeout(checkReposVariable, 5000)
|
||||
} else if (event.payload.action === 'removed_from_repository') {
|
||||
const org = event.payload.organization.login
|
||||
getTeamID(org)
|
||||
// const repo = event.payload.repository.full_name
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
function getTeamID (org) {
|
||||
function getTeamID(org) {
|
||||
const https = require('https')
|
||||
|
||||
const options = {
|
||||
|
@ -70,43 +71,30 @@ function getTeamID (org) {
|
|||
'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()
|
||||
req.end()
|
||||
}
|
||||
|
||||
function checkTeamIDVariable (repo) {
|
||||
function checkTeamIDVariable(repo) {
|
||||
if (typeof teamId != 'undefined') {
|
||||
addTeamToRepo(repo, teamId)
|
||||
}
|
||||
}
|
||||
|
||||
function checkReposVariable (org) {
|
||||
function checkReposVariable(org) {
|
||||
if (typeof orgRepos !== 'undefined') {
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
reCreateTeam(org)
|
||||
}
|
||||
}
|
||||
|
||||
function addTeamToRepo (repo, teamId) {
|
||||
function addTeamToRepo(repo, teamId) {
|
||||
const https = require('https')
|
||||
const data = JSON.stringify({
|
||||
permission: teamAccess
|
||||
|
@ -146,7 +134,7 @@ function addTeamToRepo (repo, teamId) {
|
|||
req.end()
|
||||
}
|
||||
|
||||
function reCreateTeam (org) {
|
||||
function reCreateTeam(org) {
|
||||
const https = require('https')
|
||||
const data = JSON.stringify({
|
||||
name: teamName,
|
||||
|
@ -188,7 +176,7 @@ function reCreateTeam (org) {
|
|||
req.end()
|
||||
}
|
||||
|
||||
function getRepositories (org) {
|
||||
function getRepositories(org) {
|
||||
orgRepos = []
|
||||
|
||||
const https = require('https')
|
||||
|
@ -203,20 +191,6 @@ function getRepositories (org) {
|
|||
'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)
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
var http = require('http')
|
||||
var createHandler = require('github-webhook-handler')
|
||||
var handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) })
|
||||
const http = require('http')
|
||||
const createHandler = require('github-webhook-handler')
|
||||
const handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) })
|
||||
|
||||
var userArray = ['user1']
|
||||
const userArray = ['user1']
|
||||
|
||||
var teamDescription = 'Team of Robots'
|
||||
var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
|
||||
const teamDescription = 'Team of Robots'
|
||||
const teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here
|
||||
|
||||
var teamName = process.env.GHES_TEAM_NAME
|
||||
var teamAccess = 'pull' // pull,push,admin options here
|
||||
var teamId = ''
|
||||
|
||||
var orgRepos = []
|
||||
const teamName = process.env.GHES_TEAM_NAME
|
||||
const teamAccess = 'pull' // pull,push,admin options here
|
||||
const teamId = ''
|
||||
|
||||
// var creator = ""
|
||||
|
||||
|
@ -31,61 +29,21 @@ handler.on('repository', function (event) {
|
|||
if (event.payload.action === 'created') {
|
||||
const repo = event.payload.repository.full_name
|
||||
console.log(repo)
|
||||
const org = event.payload.repository.owner.login
|
||||
getTeamID(org)
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
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') {
|
||||
// const name = event.payload.team.name
|
||||
const org = event.payload.organization.login
|
||||
getRepositories(org)
|
||||
setTimeout(checkReposVariable, 5000)
|
||||
} else if (event.payload.action === 'removed_from_repository') {
|
||||
const org = event.payload.organization.login
|
||||
getTeamID(org)
|
||||
// const repo = event.payload.repository.full_name
|
||||
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) {
|
||||
if (typeof teamId !== 'undefined') {
|
||||
addTeamToRepo(repo, teamId)
|
||||
|
@ -94,9 +52,9 @@ function checkTeamIDVariable (repo) {
|
|||
|
||||
function checkReposVariable (org) {
|
||||
if (typeof orgRepos !== 'undefined') {
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
reCreateTeam(org)
|
||||
}
|
||||
}
|
||||
|
@ -143,8 +101,7 @@ function reCreateTeam (org) {
|
|||
name: teamName,
|
||||
description: teamDescription,
|
||||
privacy: teamPrivacy,
|
||||
maintainers: userArray,
|
||||
repo_names: orgRepos
|
||||
maintainers: userArray
|
||||
})
|
||||
|
||||
const options = {
|
||||
|
@ -178,38 +135,3 @@ function reCreateTeam (org) {
|
|||
req.write(data)
|
||||
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
|
||||
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
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
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
|
||||
|
||||
var teamDescription = Team of Robots
|
||||
|
@ -18,46 +19,46 @@ var orgRepos = []
|
|||
// var creator = ""
|
||||
|
||||
var foo = someFunction();
|
||||
var bar = a + 1;
|
||||
var bar = a + 1;
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
handler(req, res, function (err) {
|
||||
console.log(err)
|
||||
res.statusCode = 404
|
||||
res.end('no such location')
|
||||
})
|
||||
}).listen(3000)
|
||||
http.createServer(function (req, res) {
|
||||
handler(req, res, function (err) {
|
||||
console.log(err)
|
||||
res.statusCode = 404
|
||||
res.end('no such location')
|
||||
})
|
||||
}).listen(3000)
|
||||
|
||||
handler.on('error', function (err) {
|
||||
console.await.error('Error:', err.message)
|
||||
})
|
||||
console.await.error('Error:', err.message)
|
||||
})
|
||||
|
||||
handler.on('repository', function (event) {
|
||||
if (event.payload.action === 'created') {
|
||||
const repo = event.payload.repository.full_name
|
||||
console.log(repo)
|
||||
const org = event.payload.repository.owner.login
|
||||
getTeamID(org)
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
if (event.payload.action === 'created') {
|
||||
const repo = event.payload.repository.full_name
|
||||
console.log(repo)
|
||||
const org = event.payload.repository.owner.login
|
||||
getTeamID(org)
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
handler.on('team', function (event) {
|
||||
// TODO user events such as being removed from team or org
|
||||
if (event.payload.action === 'deleted') {
|
||||
// const name = event.payload.team.name
|
||||
const org = event.payload.organization.login
|
||||
getRepositories(org)
|
||||
setTimeout(checkReposVariable, 5000)
|
||||
} else if (event.payload.action === 'removed_from_repository') {
|
||||
const org = event.payload.organization.login
|
||||
getTeamID(org)
|
||||
// const repo = event.payload.repository.full_name
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
// TODO user events such as being removed from team or org
|
||||
if (event.payload.action === 'deleted') {
|
||||
// const name = event.payload.team.name
|
||||
const org = event.payload.organization.login
|
||||
getRepositories(org)
|
||||
setTimeout(checkReposVariable, 5000)
|
||||
} else if (event.payload.action === 'removed_from_repository') {
|
||||
const org = event.payload.organization.login
|
||||
getTeamID(org)
|
||||
// const repo = event.payload.repository.full_name
|
||||
setTimeout(checkTeamIDVariable, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
function getTeamID (org) {
|
||||
function getTeamID(org) {
|
||||
const https = require('https')
|
||||
|
||||
const options = {
|
||||
|
@ -70,43 +71,30 @@ function getTeamID (org) {
|
|||
'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()
|
||||
req.end()
|
||||
}
|
||||
|
||||
function checkTeamIDVariable (repo) {
|
||||
function checkTeamIDVariable(repo) {
|
||||
if (typeof teamId != 'undefined') {
|
||||
addTeamToRepo(repo, teamId)
|
||||
}
|
||||
}
|
||||
|
||||
function checkReposVariable (org) {
|
||||
function checkReposVariable(org) {
|
||||
if (typeof orgRepos !== 'undefined') {
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
// for(var repo of orgRepos) {
|
||||
// addTeamToRepo(repo, teamId)
|
||||
// }
|
||||
reCreateTeam(org)
|
||||
}
|
||||
}
|
||||
|
||||
function addTeamToRepo (repo, teamId) {
|
||||
function addTeamToRepo(repo, teamId) {
|
||||
const https = require('https')
|
||||
const data = JSON.stringify({
|
||||
permission: teamAccess
|
||||
|
@ -146,7 +134,7 @@ function addTeamToRepo (repo, teamId) {
|
|||
req.end()
|
||||
}
|
||||
|
||||
function reCreateTeam (org) {
|
||||
function reCreateTeam(org) {
|
||||
const https = require('https')
|
||||
const data = JSON.stringify({
|
||||
name: teamName,
|
||||
|
@ -188,7 +176,7 @@ function reCreateTeam (org) {
|
|||
req.end()
|
||||
}
|
||||
|
||||
function getRepositories (org) {
|
||||
function getRepositories(org) {
|
||||
orgRepos = []
|
||||
|
||||
const https = require('https')
|
||||
|
@ -203,20 +191,6 @@ function getRepositories (org) {
|
|||
'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)
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
Create label in the supplied repo.
|
||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
||||
response = make_request(query, query_variables).json()
|
||||
print("Created label {label}".format(label=label["name"]))
|
||||
|
||||
return response
|
||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||
response = make_request(query, query_variables)
|
||||
|
||||
status_code = response.status_code
|
||||
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):
|
||||
"""
|
||||
Create label in the supplied repo.
|
||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
||||
response = make_request(query, query_variables).json()
|
||||
print("Created label {label}".format(label=label["name"]))
|
||||
|
||||
return response
|
||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||
response = make_request(query, query_variables).json()
|
||||
|
||||
status_code = response.status_code
|
||||
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):
|
||||
"""
|
||||
Create label in the supplied repo.
|
||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
||||
response = make_request(query, query_variables).json()
|
||||
print("Created label {label}".format(label=label["name"]))
|
||||
|
||||
return response
|
||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||
response = make_request(query, query_variables).json()
|
||||
|
||||
status_code = response.status_code
|
||||
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):
|
||||
"""
|
||||
Create label in the supplied repo.
|
||||
|
@ -51,8 +57,7 @@ def create_label(repo_id, label):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers).json()
|
||||
response = make_request(query, query_variables).json()
|
||||
print("Created label {label}".format(label=label["name"]))
|
||||
|
||||
return response
|
||||
|
@ -78,8 +83,7 @@ def get_labels(owner, repo):
|
|||
) as query_file:
|
||||
query = "".join(query_file.readlines())
|
||||
|
||||
payload = {"query": query, "variables": query_variables}
|
||||
response = requests.post(api_url, data=json.dumps(payload), headers=headers)
|
||||
response = make_request(query, query_variables).json()
|
||||
|
||||
status_code = response.status_code
|
||||
result = response.json()
|
||||
|
|
Loading…
Reference in a new issue