Skip to content

Commit

Permalink
feat: much more improve on DX and Docker (#10)
Browse files Browse the repository at this point in the history
* feat(test): add tests to stabilize util.spec.js

* feat(test): add tests for response formating on status code and message output

* feat(test): add tests to stabilize gitpath

* feat(resp): get rid of description module and merge with formatResponse module

* feat: lint and clean gitrows small errors

* feat(test): start adding tests for gitrows

* feat: removed TODO

* Updated the README

* feat(Dockerfile): upgrade the docker image

* fix: version from 0.0.3 to 0.0.4

* feat: updated the CHANGELOG and fix version on lock file

* feat(test): add test workflow
  • Loading branch information
Sanix-Darker authored May 6, 2024
1 parent feccb6c commit 32c48d2
Show file tree
Hide file tree
Showing 16 changed files with 7,459 additions and 1,041 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ node_modules
server/*.spec.js
kubernetes

.env
README.md
digest.json
screen.gif
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI Tests

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: package-lock.json

- name: Install dependencies
run: npm install

- name: Tests
run: npm test
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# CHANGESLOGS
# CHANGESLOG

## v0.0.4

### Added
- Upgraded the Docker images with the latest node (v22).

## v0.0.3

Expand Down
18 changes: 3 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# This stage installs our modules
FROM mhart/alpine-node:12
MAINTAINER [email protected]
FROM node:22

WORKDIR /app
COPY package.json package-lock.json ./

COPY package.json package-lock.json ./
RUN npm install

# Then we copy over the modules from above onto a `slim` image
FROM mhart/alpine-node:slim-12

RUN apk add --no-cache tini

WORKDIR /app
COPY --from=0 /app .
COPY . .

ENTRYPOINT ["/sbin/tini", "--"]

# Because npm is not installed here
# We will run with the node directly
CMD ["node","index.js"]
CMD ["node","index.js"]
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
# GitRowsPack-Api

Soooo, what's is gitrowspack-api in a simple sentence, it's a service interface for your (github/gitlab) repository oriented for Database !
GRP is a service interface for your (github/gitlab) repository oriented for Database (NoSQL)!
Basically, you can stored data on a repository and with this running service as the backend to access it.

It support *json*, *csv* and *yaml* file, but as default, we will be using the json.

The purpose of this project is to have a full quick running gitrows's api instance if we have our own private repos that we want to transform as storage !

![screen](./screen.gif)

## Disclaimers
This project is for certain usecases... the github API cache is HUGE, like 4/5mins, so this is not a realtime stuff, you can used in your project... but it does the job... and well !
## DISCLAIMERS

**This is a node-rest-api project inspired from an amazing npm package [gitrows](https://www.npmjs.com/package/gitrows) made by [Nicolas-Zimmer](https://github.com/nicolaszimmer) long time ago !**
This project is for certain usecases... the github API cache is HUGE, like 4/5mins, so this it's not a realtime stuff, you can use in your project.
But it does the job for data that is not going to change MORE often!

**__With a lot of improvements and bugs fixes (due to github api changes) !__**
**This is a node-rest-api service inspired from an amazing npm package [gitrows](https://www.npmjs.com/package/gitrows) made by [Nicolas-Zimmer](https://github.com/nicolaszimmer) long time ago !**

## Requirements
#### For prod
- Docker
- **__With Code improvements and some bugs fixes (due to github/gitlab api changes) !__**
- **__With CI and running tests to ensure we have everything working on new releases !__**

#### For Dev
- node/npm (see the package.json for libs)
- Docker (optionnal)
## REQUIREMENTS

## Features
Transform your github repo into a NoSQl database
- node/npm (see the package.json for deps...)
- DOCKER (optionnal)

## HOW TO SET UP

## How to set up
- Create a repository in your _github/gitlab_ profile, you can call it *'data'* for example(see mine here : https://github.com/sanix-Darker/data).
- Each directory in your project will be a *'database'* and inside, each *.json, *.csv, *.yaml is a database collection.

First, you need to create a repository in your github/gitlab profile, you can call it 'data' or whatever... but keep in mind that, each directory in your project will be a 'database' and inside there will be an 'o.json' file that will represent your collection !

Second, you just have to follow those instructions
- Follow those steps:
```bash
cd to/a/random/dir
# get the environment sample file:
Expand All @@ -48,8 +46,9 @@ https://raw.githubusercontent.com/Sanix-Darker/gitrowspack-api/master/.env.examp
# And you're all set :-)
```

## How to start it
### For prod
## HOW TO START IT

### USING THE DOCKER IMAGE

![docker-screen](./docker-screen.png)

Expand Down Expand Up @@ -81,24 +80,28 @@ sanixdarker/gitrowspack-api:latest
# curl http://127.0.0.1:3030/api/v1/<repo-name>/<database-name>/collections
```

### For dev
### BUILD YOUR OWN IMAGE

```bash
# You can build the image locally yourself
docker build --no-cache -t sanixdarker/gitrowspack-api:0.0.1 -f Dockerfile .
# And then run it locally with a valid .env
docker run --env-file .env --rm -p 3030:3030 sanixdarker/gitrowspack-api:0.0.1
```

# ----------------------------------------------------
# Or just start it manually
### NO DOCKER INVOLVES

```bash
npm install
npm start # node index.js
```

## API Documentation
## API DOCUMENTATION

You can check the API-Documentation [HERE](https://documenter.getpostman.com/view/2696027/UVREijCS)
Under a [MIT](LICENSE).


## Author
## AUTHOR

- Sanix-darker
- [dk](https://github.com/sanix-darker)
4 changes: 0 additions & 4 deletions TODO.md

This file was deleted.

50 changes: 0 additions & 50 deletions lib/descriptions.js

This file was deleted.

167 changes: 167 additions & 0 deletions lib/gitpath.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
const GitPath = require('./gitpath');
describe('GitPath', () => {
describe('parse()', () => {
it('should parse a path', () => {
const result = GitPath.parse('/path/to/file.json');
expect(result).toEqual({
valid: false,
ns: undefined,
owner: undefined,
repo: "path",
branch: undefined,
path: 'to/file.json',
type: 'json',
resource: undefined
});
});

it('should parse a GitHub URL', () => {
const result = GitPath.parse('https://github.com/owner/repo/blob/main/path/to/file.yaml');
expect(result).toEqual({
valid: true,
ns: 'github',
owner: 'owner',
repo: 'repo',
branch: 'main',
path: 'path/to/file.yaml',
type: 'yaml',
});
});

it('should parse a GitLab URL', () => {
const result = GitPath.parse('https://gitlab.com/owner/repo/-/raw/main/path/to/file.csv');
expect(result).toEqual({
valid: true,
ns: 'gitlab',
owner: 'owner',
repo: 'repo',
branch: 'main',
path: 'path/to/file.csv',
type: 'csv',
});
});

it('should return input object if already parsed', () => {
const input = {
path: 'path/to/file.json',
type: 'json'
};
const result = GitPath.parse(input);
expect(result).toBe(input);
});
});

describe('toUrl()', () => {
it('should fail generate a valid URL for an invalid/incomplete path', () => {
const result = GitPath.toUrl('/path/to/file.yaml');
expect(result).toBe(null);
});

it('should generate GitHub URL for a path', () => {
const result = GitPath.toUrl({
repo:'repo',
owner: 'owner',
ns: 'github',
path: 'path/to/file.yaml',
type: 'yaml'
});
expect(result).toBe('https://github.com/owner/repo/blob/master/path/to/file.yaml');
});

it('should generate GitLab URL for a path', () => {
const result = GitPath.toUrl({
repo:'repo',
owner: 'owner',
ns: 'gitlab',
path: 'path/to/file.json',
type: 'json'
});
expect(result).toBe('https://gitlab.com/owner/repo/-/blob/master/path/to/file.json');
});

it('should handle raw parameter', () => {
const result = GitPath.toUrl({
repo:'repo',
owner: 'owner',
ns: 'github',
path: 'path/to/file.csv',
type: 'csv'
}, true);
expect(result).toBe('https://raw.githubusercontent.com/owner/repo/master/path/to/file.csv');
});

});

describe('toApi()', () => {
it('should generate GitHub API URL for a path', () => {
const result = GitPath.toApi({
repo:'repo',
owner: 'owner',
ns: 'github',
path: 'path/to/file.json',
type: 'json'
});
expect(result).toBe('https://api.github.com/repos/owner/repo/contents/path/to/file.json');
});

it('should generate GitLab API URL for a path', () => {
const result = GitPath.toApi({
repo:'repo',
owner: 'owner',
ns: 'gitlab',
path: 'path/to/file.yaml',
type: 'yaml'
});
expect(result).toBe('https://gitlab.com/api/v4/projects/owner%2Frepo/repository/files/path%2Fto%2Ffile.yaml');
});
});

describe('isValid()', () => {
it('should return true for a valid object', () => {
const obj = {
ns: "github",
owner: 'owner',
repo: 'repo',
path: 'path/to/file.json',
type: 'json'
};
const result = GitPath.isValid(obj);
expect(result).toBe(true);
});

it('should return false if type is invalid', () => {
const obj = {
ns: undefined,
owner: 'owner',
repo: 'repo',
path: 'path/to/file.json',
type: 'invalid'
};
const result = GitPath.isValid(obj);
expect(result).toBe(false);
});

it('should return false if mandatory properties are missing', () => {
const obj = {
ns: undefined,
owner: 'owner',
repo: 'repo',
type: 'json'
};
const result = GitPath.isValid(obj);
expect(result).toBe(false);
});
});

describe('isUrl()', () => {
it('should return true for a valid URL', () => {
const result = GitPath.isUrl('https://github.com/owner/repo/blob/main/path/to/file.yaml');
expect(result).toBe(true);
});

it('should return false for an invalid URL', () => {
const result = GitPath.isUrl('/path/to/file.yaml');
expect(result).toBe(false);
});
});
});
Loading

0 comments on commit 32c48d2

Please sign in to comment.