Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laying the groundwork for the git refactor #50

Merged
merged 50 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a4af6c1
Laying the groundwork for the `git` refactor
confused-Techie Jan 11, 2023
d46a55a
Use `switch` for comparison, remove `lowercase()` external usage
confused-Techie Jan 12, 2023
0a13702
Added Codeberg VCS detection
confused-Techie Jan 12, 2023
53f3fce
Avoid semicolon auto-insertion, start specifying git class
confused-Techie Jan 12, 2023
76728aa
Framework of VCS Services, and testing them
confused-Techie Jan 12, 2023
f05b84d
Full testing suite written for GitHub `doesUserHaveRepo`
confused-Techie Jan 12, 2023
f4292dc
Updated `codeql` to ignore new testing location
confused-Techie Jan 12, 2023
1ccf4ae
Update fixture file name
confused-Techie Jan 12, 2023
67d4cbb
Move heavy lifting into `github.js` for ownership returns
confused-Techie Jan 12, 2023
abbbaa8
Fix typo `unkown` => `unknown`
confused-Techie Jan 13, 2023
60de1c4
Use new endpoint to find user ownership, new tests
confused-Techie Jan 13, 2023
33fbfab
`readme` & docs
confused-Techie Jan 13, 2023
d1140a3
Some more tests for new `readme` function
confused-Techie Jan 13, 2023
c77dfd4
Additional layout of core API structure
confused-Techie Jan 14, 2023
5ce374b
Merge branch 'main' into refactor-git
confused-Techie Jan 14, 2023
af71577
fix CodeQL issues
Digitalone1 Jan 14, 2023
872d107
github class: use const where possible
Digitalone1 Jan 14, 2023
850ea37
use an internal initializer and introduce private properties
Digitalone1 Jan 14, 2023
89e755a
camelCase properties + fix base class setters
Digitalone1 Jan 14, 2023
f3b609d
git class: remove setters and add jsdoc to methods
Digitalone1 Jan 15, 2023
fd84d66
Complete the specific components of the GitHub VCS Module
confused-Techie Jan 17, 2023
e0a4ddd
Fixed Undeclared Variable
confused-Techie Jan 17, 2023
2919648
Fix Syntax Error
confused-Techie Jan 17, 2023
d88fca7
Documentation, and refining exports and scope of responsibilites
confused-Techie Jan 17, 2023
fd69cf8
Progress on Publishing functionality
confused-Techie Jan 17, 2023
ee592e6
Some comments
confused-Techie Jan 17, 2023
d802f4b
Finish `newPackageData` begin fleshing out other functions
confused-Techie Jan 18, 2023
cfbd3a3
Fixed syntax error on ternary operator
confused-Techie Jan 18, 2023
9c92be4
Methodology to reduce repetitious package handling
confused-Techie Jan 18, 2023
d69a4c8
Initial construction of `package_json` class
confused-Techie Jan 19, 2023
99c2c8c
Continuing work on having easy interactions with package.json data
confused-Techie Jan 19, 2023
00dd86c
Merge remote-tracking branch 'upstream/refactor-git' into refactor-git
Digitalone1 Jan 19, 2023
bbddd30
fix CodeQL issues + typeof to check "function"
Digitalone1 Jan 19, 2023
080a7b7
Merge pull request #56 from Digitalone1/refactor-git
confused-Techie Jan 19, 2023
f7480f4
timestamps set by PostgreSQL by default
Digitalone1 Jan 19, 2023
f79cbf1
fix lexical scoping in switch
Digitalone1 Jan 19, 2023
d15d39f
downloads and stars count auto-initialized by PostgreSQL to 0
Digitalone1 Jan 19, 2023
de4bdc4
Merge pull request #61 from Digitalone1/refactor-git
confused-Techie Jan 22, 2023
7590a47
Fully Tested `vcs.newPackageData`
confused-Techie Jan 23, 2023
45a5543
Fully tested `newVersionData` agnostic logic after service selection
confused-Techie Jan 23, 2023
82e1ce9
Ownership tests, removed pseudo objects
confused-Techie Jan 23, 2023
48a93b5
`deletePackageName` & `postPackageVersion` using VCS + Removed Outdat…
confused-Techie Jan 24, 2023
3848b4c
Merge branch 'main' into refactor-git
confused-Techie Feb 5, 2023
408ac9e
Fix the failing test from generic test runners
confused-Techie Feb 5, 2023
ea97df1
Utilize VCS for `deletePackagesName`
confused-Techie Feb 5, 2023
ac5bf87
Update `postPackagesVersion` use VCS auth for `deletePackagesVersion`…
confused-Techie Feb 5, 2023
ab93fcb
Better docs, publishPackage auth feature added to `vcs.ownership()`
confused-Techie Feb 5, 2023
816cf70
Slight Refactor on VCS
confused-Techie Feb 5, 2023
74861ec
Remove final usage of `git` in `package_handler.js`
confused-Techie Feb 5, 2023
53cba5f
Remove unused variable
confused-Techie Feb 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codeql-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ queries:
paths-ignore:
- ./src/tests
- ./src/tests_integration
- ./src/vcs_providers_tests
# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors
9 changes: 8 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ const config = {
globalSetup: "<rootDir>/node_modules/@databases/pg-test/jest/globalSetup",
globalTeardown:
"<rootDir>/node_modules/@databases/pg-test/jest/globalTeardown",
testMatch: ["<rootDir>/src/tests_integration/*.test.js"],
testMatch: ["<rootDir>/src/tests_integration/main.test.js"],
},
{
displayName: "Unit-Tests",
testMatch: ["<rootDir>/src/tests/*.test.js"],
},
{
displayName: "VCS-Tests",
testMatch: [
"<rootDir>/src/vcs_providers_tests/**/*.test.js",
"<rootDir>/src/vcs_providers_tests/*.test.js"
],
}
],
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test:integration": "cross-env NODE_ENV=test PULSAR_STATUS=dev jest --selectProjects Integration-Tests",
"start:dev": "cross-env PULSAR_STATUS=dev node ./src/dev_server.js",
"test": "cross-env NODE_ENV=test PULSAR_STATUS=dev jest",
"test:vcs": "cross-env NODE_ENV=test PULSAR_STATUS=dev MOCK_GH=false jest --selectProjects VCS-Tests",
"api-docs": "quick-webserver-docs -i ./src/main.js -o ./docs/reference/API_Definition.md",
"lint": "prettier --check -u -w .",
"complex": "cr --newmi --config .complexrc .",
Expand Down
115 changes: 65 additions & 50 deletions src/handlers/package_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const common = require("./common_handler.js");
const query = require("../query.js");
const git = require("../git.js");
const vcs = require("../vcs.js");
const logger = require("../logger.js");
const { server_url } = require("../config.js").getConfig();
const utils = require("../utils.js");
Expand Down Expand Up @@ -420,9 +421,13 @@ async function deletePackagesName(req, res) {
return;
}

const gitowner = await git.ownership(
//const gitowner = await git.ownership(
// user.content,
// utils.getOwnerRepoFromPackage(packageExists.content.data)
//);
const gitowner = await vcs.ownership(
user.content,
utils.getOwnerRepoFromPackage(packageExists.content.data)
packageExists.content
);

if (!gitowner.ok) {
Expand Down Expand Up @@ -628,61 +633,70 @@ async function postPackagesVersion(req, res) {
// Get `owner/repo` string format from package.
let ownerRepo = utils.getOwnerRepoFromPackage(packExists.content.data);

// Now it's important to note, that getPackageJSON was intended to be an internal function.
// As such does not return a Server Status Object. This may change later, but for now,
// we will expect `undefined` to not be success.
const packJSON = await git.getPackageJSON(ownerRepo, user.content);
// Using our new VCS Service
// TODO: The "git" Service shouldn't always be hardcoded.
let packMetadata = await vcs.newVersionData(user.content, ownerRepo, "git");

if (packJSON === undefined) {
logger.generic(6, `Unable to get Package JSON from git with: ${ownerRepo}`);
await common.handleError(req, res, {
ok: false,
short: "Bad Package",
content: `Failed to get Package JSON: ${ownerRepo}`,
});
if (!packMetadata.ok) {
logger.generic(6, packMetadata.content);
await common.handleError(req, res, packMetadata);
return;
}
// Now it's important to note, that getPackageJSON was intended to be an internal function.
// As such does not return a Server Status Object. This may change later, but for now,
// we will expect `undefined` to not be success.
//const packJSON = await git.getPackageJSON(ownerRepo, user.content);

//if (packJSON === undefined) {
// logger.generic(6, `Unable to get Package JSON from git with: ${ownerRepo}`);
// await common.handleError(req, res, {
// ok: false,
// short: "Bad Package",
// content: `Failed to get Package JSON: ${ownerRepo}`,
// });
// return;
//}

// Now we will also need to get the packages data to update on the db
// during version pushes.

const packReadme = await git.getRepoReadMe(ownerRepo, user.content);
//const packReadme = await git.getRepoReadMe(ownerRepo, user.content);
// Again important to note, this was intended as an internal function of git
// As such does not return a Server Status Object, and instead returns the obj or null
if (packReadme === undefined) {
logger.generic(
6,
`Unable to Get Package Readme from git with: ${ownerRepo}`
);
await common.handleError(req, res, {
ok: false,
short: "Bad Package",
content: `Failed to get Package Readme: ${ownerRepo}`,
});
}

const packMetadata = await git.metadataAppendTarballInfo(
packJSON,
packJSON.version,
user.content
);
if (packMetadata === undefined) {
await common.handleError(req, res, {
ok: false,
short: "Bad Package",
content: `Failed to get Package metadata info: ${ownerRepo}`,
});
}
//if (packReadme === undefined) {
// logger.generic(
// 6,
// `Unable to Get Package Readme from git with: ${ownerRepo}`
// );
// await common.handleError(req, res, {
// ok: false,
// short: "Bad Package",
// content: `Failed to get Package Readme: ${ownerRepo}`,
// });
//}

//const packMetadata = await git.metadataAppendTarballInfo(
// packJSON,
// packJSON.version,
// user.content
//);
//if (packMetadata === undefined) {
// await common.handleError(req, res, {
// ok: false,
// short: "Bad Package",
// content: `Failed to get Package metadata info: ${ownerRepo}`,
// });
//}

// Now construct the object that will be used to update the `data` column.
const packageData = {
name: packMetadata.name.toLowerCase(),
repository: git.selectPackageRepository(packMetadata.repository),
readme: packReadme,
metadata: packMetadata,
};

const newName = packMetadata.name;
//const packageData = {
// name: packMetadata.name.toLowerCase(),
// repository: git.selectPackageRepository(packMetadata.repository),
// readme: packReadme,
// metadata: packMetadata,
//};

const newName = packMetadata.content.metadata.name;
const currentName = packExists.content.name;
if (newName !== currentName && !params.rename) {
logger.generic(
Expand All @@ -705,9 +719,10 @@ async function postPackagesVersion(req, res) {
// From the newest updated `package.json` info, just in case it's changed that will be
// supported here

ownerRepo = utils.getOwnerRepoFromPackage(packJSON);
ownerRepo = utils.getOwnerRepoFromPackage(packMetadata.content.metadata);

Check warning

Code scanning / CodeQL

Useless assignment to local variable

The value assigned to ownerRepo here is unused.

const gitowner = await git.ownership(user.content, ownerRepo);
//const gitowner = await git.ownership(user.content, ownerRepo);
const gitowner = await vcs.ownership(user.content, packExists.content);

if (!gitowner.ok) {
logger.generic(6, `User Failed Git Ownership Check: ${gitowner.content}`);
Expand Down Expand Up @@ -740,8 +755,8 @@ async function postPackagesVersion(req, res) {
// Now add the new Version key.

const addVer = await database.insertNewPackageVersion(
packMetadata,
packageData,
packMetadata.content.metadata,
packageMetadata.content,
rename ? currentName : null
);

Expand Down
62 changes: 62 additions & 0 deletions src/tests/vcs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const vcs = require("../vcs.js");

describe("determineProvider Returns as expected", () => {
test("Returns null when no input is passed", () => {
const res = vcs.determineProvider();
expect(res.type).toBe("na");
expect(res.url).toBe("");
});
test("Returns null when null input is passed", () => {
const res = vcs.determineProvider(null);
expect(res.type).toBe("na");
expect(res.url).toBe("");
});
test("Returns proper object, when object is passed", () => {
const tmp = { type: "git", url: "https://github.com/confused-Techie/atom-backend" };
const res = vcs.determineProvider(tmp);
expect(res.type).toBe(tmp.type);
expect(res.url).toBe(tmp.url);
});
test("Returns unknown VCS Object, when unkown is passed", () => {
const tmp = "https://new-vcs.com/pulsar-edit/pulsar";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("unknown");
expect(res.url).toBe(tmp);
});
test("Returns unkown string when passed invalid data", () => {
const tmp = 123;
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("unknown");
expect(res.url).toBe(tmp);
});
test("Returns proper GitHub Object, passed GitHub string", () => {
const tmp = "https://github.com/confused-Techie/atom-backend";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("git");
expect(res.url).toBe(tmp);
});
test("Returns proper GitLab Object, passed GitLab string", () => {
const tmp = "https://gitlab.com/clj-editors/atom-chlorine";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("lab");
expect(res.url).toBe(tmp);
});
test("Returns proper Sourceforge Object, when passed Sourceforge string", () => {
const tmp = "https://sourceforge.net/projects/jellyfin.mirror/";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("sfr");
expect(res.url).toBe(tmp);
});
test("Returns proper Bitbucket Object, when passed Bitbucket string", () => {
const tmp = "https://bitbucket.org/docker_alpine/alpine-jellyfin/src/master/";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("bit");
expect(res.url).toBe(tmp);
});
test("Returns proper Codeberg Object, when passed Codeberg string", () => {
const tmp = "https://codeberg.org/itbastian/makemkv-move-extras";
const res = vcs.determineProvider(tmp);
expect(res.type).toBe("berg");
expect(res.url).toBe(tmp);
});
});
Loading