From 42781ed092a582875a1c9270db2e4728b66b5613 Mon Sep 17 00:00:00 2001 From: KillWolfVlad Date: Mon, 23 Oct 2023 17:30:46 +0500 Subject: [PATCH] feat: add initial source --- .github/workflows/cron.yaml | 18 +++++++++++++++ README.md | 1 + package.json | 20 +++++++++++++++++ suggestions.json | 4 ++++ upvote.test.js | 44 +++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 .github/workflows/cron.yaml create mode 100644 package.json create mode 100644 suggestions.json create mode 100644 upvote.test.js diff --git a/.github/workflows/cron.yaml b/.github/workflows/cron.yaml new file mode 100644 index 0000000..b6345be --- /dev/null +++ b/.github/workflows/cron.yaml @@ -0,0 +1,18 @@ +name: cron + +on: + workflow_dispatch: + schedule: + - cron: "*/55 * * * *" # every 55th minute + +jobs: + ############################################################################## + upvote: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-node@v3 + with: + node-version: lts/* + + - run: yarn run test diff --git a/README.md b/README.md index b1a8a92..c5d94b4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # gk-upvote + Script for auto voting on GitKraken feedback website diff --git a/package.json b/package.json new file mode 100644 index 0000000..5cc9b68 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "gk-upvote", + "version": "0.0.0-development", + "private": true, + "description": "Script for auto voting on GitKraken feedback website", + "homepage": "https://github.com/KillWolfVlad/gk-upvote#readme", + "bugs": { + "url": "https://github.com/KillWolfVlad/gk-upvote/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/KillWolfVlad/gk-upvote.git" + }, + "license": "UNLICENSED", + "author": "KillWolfVlad", + "type": "module", + "scripts": { + "test": "node --test" + } +} diff --git a/suggestions.json b/suggestions.json new file mode 100644 index 0000000..e2455cd --- /dev/null +++ b/suggestions.json @@ -0,0 +1,4 @@ +[ + "https://feedback.gitkraken.com/suggestions/191565/support-sshconfig-file", + "https://feedback.gitkraken.com/suggestions/194039/support-multiple-gitkraken-windows" +] diff --git a/upvote.test.js b/upvote.test.js new file mode 100644 index 0000000..337e0f2 --- /dev/null +++ b/upvote.test.js @@ -0,0 +1,44 @@ +import assert from "node:assert"; +import { describe, it } from "node:test"; + +import suggestions from "./suggestions.json" assert { type: "json" }; + +describe("Upvote", () => { + for (const suggestion of suggestions) { + it(suggestion, async () => { + const feedbackId = suggestion.match(/\/suggestions\/(\d+)\//)[1]; + + const htmlResponse = await fetch( + `https://feedback.gitkraken.com/suggestions/${encodeURIComponent( + feedbackId + )}` + ); + + const html = await htmlResponse.text(); + + const csrfToken = html.match( + // + )[1]; + + const formData = new FormData(); + + formData.append("csrf_token", csrfToken); + formData.append("ts", new Date().getTime()); + + const toggleUpvoteResult = await fetch( + `https://feedback.gitkraken.com/s/${encodeURIComponent( + feedbackId + )}/toggleupvote`, + { + method: "POST", + body: formData, + headers: { + cookie: htmlResponse.headers.getSetCookie().join(";"), + }, + } + ).then((response) => response.text()); + + assert.strictEqual(toggleUpvoteResult, "OK"); + }); + } +});