From dd929af281929892a1254b9bd2cfb811d9eb7196 Mon Sep 17 00:00:00 2001 From: Philipp Horstenkamp Date: Sun, 26 Nov 2023 20:50:28 +0100 Subject: [PATCH] Reworkeed the function to use Promice resolve --- index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e526b20..041f5e0 100644 --- a/index.js +++ b/index.js @@ -114,14 +114,26 @@ async function postCode() { let api; if (token) { api = new ScreepsAPI(login_arguments); + const response = await api.code.set(branch, files_to_push); + core.info(JSON.stringify(response, null, 2)); } else { core.info(`Logging into as user ${username}`); - api = new ScreepsAPI(login_arguments); - await api.auth(username, password); + const response = Promise.resolve() + .then(() => api.auth(auth.email, auth.password)) + .then(() => api.socket.connect()) + .then(() => { + return api.code.set(branch, code); // Set the code on the specified branch + }) + .then(() => { + console.log("Code set successfully"); + // Additional actions after setting the code, if necessary + }) + .catch((err) => { + console.error("Error:", err); + }); core.info("Authorized!"); + core.info(JSON.stringify(response, null, 2)); } - const response = await api.code.set(branch, files_to_push); - core.info(JSON.stringify(response, null, 2)); } postCode();