Added auth for private servers (#7)
Lint / pre-commit Linting (push) Successful in 45s Details

Reviewed-on: #7
Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de>
Co-committed-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
Philipp Horstenkamp 2023-11-26 22:24:16 +01:00 committed by Philipp Horstenkamp
parent 6f5729c12a
commit e7678a5f66
1 changed files with 23 additions and 10 deletions

View File

@ -90,12 +90,11 @@ async function postCode() {
const files_to_push = await readFilesIntoDict(pattern, prefix);
core.info(`Trying to upload the following files to ${branch}:`);
Object.keys(files_to_push).forEach((key) => {
core.info(`Key: ${key}`);
});
core.info(files_to_push);
const login_arguments = {
token: token,
username: username,
@ -106,20 +105,34 @@ async function postCode() {
path: path,
};
core.info(`Trying to upload the following files to ${branch}:`);
Object.keys(login_arguments).forEach((key) => {
core.info(`Key: ${key}`);
});
core.info("login_arguments:");
core.info(JSON.stringify(login_arguments, null, 2));
const errorMessage = validateAuthentication(token, username, password);
if (errorMessage) {
core.error(errorMessage);
return;
}
const api = new ScreepsAPI(login_arguments);
const response = await api.code.set(branch, files_to_push);
core.info(JSON.stringify(response, null, 2));
let api = new ScreepsAPI(login_arguments);
if (token) {
const response = await api.code.set(branch, files_to_push);
core.info(JSON.stringify(response, null, 2));
console.log(`Code set successfully to ${branch}`);
} else {
let response;
core.info(`Logging in as user ${username}`);
response = await Promise.resolve()
.then(() => api.auth(username, password, login_arguments))
.then(() => {
api.code.set(branch, files_to_push);
})
.then(() => {
console.log(`Code set successfully to ${branch}`);
})
.catch((err) => {
console.error("Error:", err);
});
}
}
postCode();