WIP Gitea issue search request

This commit is contained in:
Alan O'Cull 2024-01-11 18:15:59 -05:00
parent 5f36417a82
commit d7e0cf09fd
4 changed files with 131 additions and 4771 deletions

View File

@ -1,4 +1,10 @@
{ {
"gitea": "https://git.alanocull.com", "gitea": "https://git.alanocull.com",
"port": 3001 "port": 3001,
"repositories": {
"game": "triple-aaa-games/hook-line-axe",
"asset": "triple-aaa-games/assets",
"bot": "triple-aaa-games/gitea-jira"
},
"repository-default": "bot"
} }

4832
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,8 @@
"author": "Alan O'Cull, Triple AAA Games", "author": "Alan O'Cull, Triple AAA Games",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"atlassian-connect-express": "^8.7.0", "body-parser": "^1.20.2",
"express": "^4.18.2" "express": "^4.18.2",
"lodash": "^4.17.21"
} }
} }

View File

@ -1,4 +1,7 @@
const fs = require('fs'); const fs = require('fs');
const https = require('https');
const bodyParser = require('body-parser');
const _ = require('lodash');
const express = require('express'); const express = require('express');
const { append } = require('express/lib/response'); const { append } = require('express/lib/response');
@ -11,30 +14,56 @@ const PORT = CONFIG['port'];
// BUILD OAUTH // BUILD OAUTH
const OAUTH_JIRA = `${SECRETS['jira-email']}:${SECRETS['jira-token']}`; const OAUTH_JIRA = `${SECRETS['jira-email']}:${SECRETS['jira-token']}`;
const OAUTH_GITEA = `token ${SECRETS['gitea-token']}`; const OAUTH_GITEA = `token=${SECRETS['gitea-token']}`;
const URL_GITEA = `${CONFIG['gitea']}/api`; const URL_GITEA = `${CONFIG['gitea']}/api/v1`;
// INITIALIZE EXPRESS // INITIALIZE EXPRESS AND SET UP WEBHOOKS
const app = express(); const app = express();
app.use(bodyParser.json());
// FUNCTIONALITY
// SET UP WEBHOOKS
app.get('/', (req, res) => { app.get('/', (req, res) => {
console.log("Got request ", req.url); console.log("Got request ", req.url);
res.send({'data':'nice'}); res.send({'data':'nice'});
}) })
// FUNCTIONALITY
const fetch_issues = () => {
/** @type {Object} */
_.forEach(CONFIG['repositories'], (loc, key) => {
console.log(`KEY [${key}]: ${loc}`);
if (key !== 'bot') { return } // TESTING ONLY, skip if not bot repo
// Search for all open issues in the given repository
const reqURL = `${URL_GITEA}/repos/${loc}/issues?state=open&${OAUTH_GITEA}`;
const options = {
hostname: URL_GITEA,
port: 443,
path: `/repos/${loc}/issues?state=open&${OAUTH_GITEA}`,
method: 'GET',
accept: 'application/json'
};
console.log(`Sending request to ${reqURL}`);
const req = https.request(options, (res) => {
res.setEncoding('utf-8');
res.on('data', (d) => {
console.log(d);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
});
}
fetch_issues();
// HOST // HOST
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`Server is running on localhost:${PORT}, working in ${CONFIG_DIRECTORY}`) console.log(`Server is running on localhost:${PORT}, working in ${CONFIG_DIRECTORY}`)
}); });
app.post(`${URL_GITEA}/repos/triple-aaa-games/hook-line-axe/issues`, (req, res) => {
console.log(req.body);
});