├── index.js ├── .gitignore ├── src ├── modules │ └── Api.ts ├── utils │ └── RandomNumber.ts ├── tests │ ├── findall.test.ts │ ├── delete.test.ts │ ├── find.test.ts │ ├── update.test.ts │ ├── create.test.ts │ └── connection.test.ts └── index.ts ├── dist └── src │ ├── definitions.js │ ├── definitions.js.map │ ├── modules │ ├── Api.js.map │ └── Api.js │ ├── utils │ ├── RandomNumber.js │ └── RandomNumber.js.map │ ├── tests │ ├── findall.test.js.map │ ├── delete.test.js.map │ ├── update.test.js.map │ ├── find.test.js.map │ ├── create.test.js.map │ ├── connection.test.js.map │ ├── findall.test.js │ ├── delete.test.js │ ├── update.test.js │ ├── find.test.js │ ├── create.test.js │ └── connection.test.js │ ├── index.js.map │ └── index.js ├── .vscode └── settings.json ├── .github └── main.workflow ├── tsconfig.json ├── LICENSE ├── tslint.json ├── .circleci └── config.yml ├── index.d.ts ├── package.json └── README.md /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./dist/src/index.js') 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # node modules 2 | /node_modules 3 | 4 | # environmental 5 | .env -------------------------------------------------------------------------------- /src/modules/Api.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | export default axios.create({ 4 | baseURL: 'https://api.github.com' 5 | }) 6 | -------------------------------------------------------------------------------- /dist/src/definitions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=definitions.js.map -------------------------------------------------------------------------------- /dist/src/definitions.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/src/modules/Api.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Api.js","sourceRoot":"","sources":["../../../src/modules/Api.ts"],"names":[],"mappings":";;AAAA,iCAAyB;AAEzB,kBAAe,eAAK,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,wBAAwB;CACjC,CAAC,CAAA"} -------------------------------------------------------------------------------- /src/utils/RandomNumber.ts: -------------------------------------------------------------------------------- 1 | export default function generateRandomNumber(min: number, max: number) { 2 | min = Math.ceil(min) 3 | max = Math.floor(max) 4 | return Math.floor(Math.random() * (max - min)) + min 5 | } 6 | -------------------------------------------------------------------------------- /dist/src/modules/Api.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const axios_1 = require("axios"); 4 | exports.default = axios_1.default.create({ 5 | baseURL: 'https://api.github.com' 6 | }); 7 | //# sourceMappingURL=Api.js.map -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "path-autocomplete.pathMappings": { 4 | "~": "${folder}/src" 5 | }, 6 | "editor.tabSize": 2, 7 | "editor.autoIndent": true, 8 | "editor.detectIndentation": true, 9 | "prettier-tslint.tslintIntegration": true 10 | } 11 | -------------------------------------------------------------------------------- /dist/src/utils/RandomNumber.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function generateRandomNumber(min, max) { 4 | min = Math.ceil(min); 5 | max = Math.floor(max); 6 | return Math.floor(Math.random() * (max - min)) + min; 7 | } 8 | exports.default = generateRandomNumber; 9 | //# sourceMappingURL=RandomNumber.js.map -------------------------------------------------------------------------------- /.github/main.workflow: -------------------------------------------------------------------------------- 1 | workflow "Deploy" { 2 | on = "push" 3 | resolves = ["Install"] 4 | } 5 | 6 | # Only run on `master` branch 7 | action "Master" { 8 | uses = "actions/bin/filter@master" 9 | args = "branch master" 10 | } 11 | 12 | # `npm ci` 13 | action "Install" { 14 | uses = "actions/npm@master" 15 | args = "ci" 16 | needs = ["Master"] 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "resolveJsonModule": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "rootDir": ".", 7 | "outDir": "dist", 8 | "allowJs": true, 9 | "sourceMap": true, 10 | "baseUrl": "./src", 11 | "paths": { 12 | "~/*": ["app/*"] 13 | } 14 | }, 15 | "include": ["src/**/*.ts", "index.d.ts"], 16 | "exclude": ["node_modules", ".vscode"] 17 | } 18 | -------------------------------------------------------------------------------- /dist/src/utils/RandomNumber.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"RandomNumber.js","sourceRoot":"","sources":["../../../src/utils/RandomNumber.ts"],"names":[],"mappings":";;AAAA,SAAwB,oBAAoB,CAAC,GAAW,EAAE,GAAW;IACpE,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AACrD,CAAC;AAJD,uCAIC"} -------------------------------------------------------------------------------- /src/tests/findall.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | 5 | describe('=> GET Request', () => { 6 | let Gitorm: gitorm 7 | 8 | before(async () => { 9 | Gitorm = new gitorm({ 10 | token: process.env.GIT_TOKEN, 11 | repository: process.env.GIT_REPOSITORY, 12 | owner: process.env.GIT_OWNER 13 | }) 14 | 15 | await Gitorm.connect() 16 | }) 17 | 18 | it('Should get all files', async () => { 19 | const files = await Gitorm.findAll({ path: 'src/' }) 20 | assert.notStrictEqual(files, false) 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /dist/src/tests/findall.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"findall.test.js","sourceRoot":"","sources":["../../../src/tests/findall.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAEhC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAc,CAAA;IAElB,MAAM,CAAC,GAAS,EAAE;QACjB,MAAM,GAAG,IAAI,eAAM,CAAC;YACnB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,sBAAsB,EAAE,GAAS,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;QACpD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACpC,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /src/tests/delete.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | import generateRandomNumber from '../utils/RandomNumber' 5 | 6 | describe('=> DELETE Request', () => { 7 | let Gitorm: gitorm 8 | let fileName: string 9 | 10 | before(async () => { 11 | Gitorm = new gitorm({ 12 | token: process.env.GIT_TOKEN, 13 | repository: process.env.GIT_REPOSITORY, 14 | owner: process.env.GIT_OWNER 15 | }) 16 | 17 | await Gitorm.connect() 18 | fileName = `test${generateRandomNumber(0, 1e10)}` 19 | }) 20 | 21 | it('Should delete a file', async () => { 22 | const data = JSON.stringify({ teste: 123 }) 23 | const file: any = await Gitorm.create({ 24 | data, 25 | path: 'src/' + `${fileName}.json` 26 | }) 27 | 28 | const isFileDeleted = await Gitorm.delete({ path: file.path }) 29 | 30 | assert.notStrictEqual(isFileDeleted, false) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /src/tests/find.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | 5 | describe('=> GET Request', () => { 6 | let Gitorm: gitorm 7 | 8 | before(async () => { 9 | Gitorm = new gitorm({ 10 | token: process.env.GIT_TOKEN, 11 | repository: process.env.GIT_REPOSITORY, 12 | owner: process.env.GIT_OWNER 13 | }) 14 | 15 | await Gitorm.connect() 16 | }) 17 | 18 | it('Should get a file', async () => { 19 | const file = await Gitorm.find({ path: 'src/' + 'index.txt' }) 20 | assert.notStrictEqual(file, false) 21 | }) 22 | 23 | it('Should fail to get file with incorrect [path]', async () => { 24 | const file = await Gitorm.find({ path: 'src/123/' + 'index.txt' }) 25 | assert.strictEqual(file, false) 26 | }) 27 | 28 | it('Should fail to get file with incorrect [name]', async () => { 29 | const file = await Gitorm.find({ path: 'src/' + 'index.png' }) 30 | assert.strictEqual(file, false) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /dist/src/tests/delete.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"delete.test.js","sourceRoot":"","sources":["../../../src/tests/delete.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAChC,wDAAwD;AAExD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,IAAI,MAAc,CAAA;IAClB,IAAI,QAAgB,CAAA;IAEpB,MAAM,CAAC,GAAS,EAAE;QACjB,MAAM,GAAG,IAAI,eAAM,CAAC;YACnB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,QAAQ,GAAG,OAAO,sBAAoB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAA;IAClD,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,sBAAsB,EAAE,GAAS,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAQ,MAAM,MAAM,CAAC,MAAM,CAAC;YACrC,IAAI;YACJ,IAAI,EAAE,MAAM,GAAG,GAAG,QAAQ,OAAO;SACjC,CAAC,CAAA;QAEF,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAE9D,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /src/tests/update.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | import generateRandomNumber from '../utils/RandomNumber' 5 | 6 | describe('=> PUT Request', () => { 7 | let Gitorm: gitorm 8 | let fileName: string 9 | 10 | before(async () => { 11 | Gitorm = new gitorm({ 12 | token: process.env.GIT_TOKEN, 13 | repository: process.env.GIT_REPOSITORY, 14 | owner: process.env.GIT_OWNER 15 | }) 16 | 17 | await Gitorm.connect() 18 | fileName = `test${generateRandomNumber(0, 1e10)}` 19 | }) 20 | 21 | it('Should update a file', async () => { 22 | const data = JSON.stringify({ teste: 123 }) 23 | const file: any = await Gitorm.create({ 24 | data, 25 | path: 'src/' + `${fileName}.json` 26 | }) 27 | 28 | const newData = JSON.stringify({ teste: 321 }) 29 | const updatedFile = await Gitorm.update({ 30 | data: newData, 31 | path: file.path 32 | }) 33 | 34 | assert.notStrictEqual(updatedFile, false) 35 | }) 36 | }) 37 | -------------------------------------------------------------------------------- /dist/src/tests/update.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"update.test.js","sourceRoot":"","sources":["../../../src/tests/update.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAChC,wDAAwD;AAExD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAc,CAAA;IAClB,IAAI,QAAgB,CAAA;IAEpB,MAAM,CAAC,GAAS,EAAE;QACjB,MAAM,GAAG,IAAI,eAAM,CAAC;YACnB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,QAAQ,GAAG,OAAO,sBAAoB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAA;IAClD,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,sBAAsB,EAAE,GAAS,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAQ,MAAM,MAAM,CAAC,MAAM,CAAC;YACrC,IAAI;YACJ,IAAI,EAAE,MAAM,GAAG,GAAG,QAAQ,OAAO;SACjC,CAAC,CAAA;QAEF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAC9C,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;YACvC,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;SACf,CAAC,CAAA;QAEF,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;IAC1C,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /src/tests/create.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | import generateRandomNumber from '../utils/RandomNumber' 5 | 6 | describe('=> POST Request', () => { 7 | let Gitorm: gitorm 8 | let fileName: string 9 | 10 | before(async () => { 11 | Gitorm = new gitorm({ 12 | token: process.env.GIT_TOKEN, 13 | repository: process.env.GIT_REPOSITORY, 14 | owner: process.env.GIT_OWNER 15 | }) 16 | 17 | await Gitorm.connect() 18 | fileName = `test${generateRandomNumber(0, 1e10)}` 19 | }) 20 | 21 | it('Should create a file', async () => { 22 | const data = JSON.stringify({ teste: 123 }) 23 | const file = await Gitorm.create({ 24 | data, 25 | path: 'src/' + `${fileName}.json` 26 | }) 27 | assert.notStrictEqual(file, false) 28 | }) 29 | 30 | it('Should fail to create a file that already exists', async () => { 31 | const data = JSON.stringify({ teste: 123 }) 32 | const file = await Gitorm.create({ 33 | data, 34 | path: 'src/' + `${fileName}.json` 35 | }) 36 | assert.strictEqual(file, false) 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /dist/src/tests/find.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"find.test.js","sourceRoot":"","sources":["../../../src/tests/find.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAEhC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAc,CAAA;IAElB,MAAM,CAAC,GAAS,EAAE;QACjB,MAAM,GAAG,IAAI,eAAM,CAAC;YACnB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,mBAAmB,EAAE,GAAS,EAAE;QAClC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC,CAAA;QAC9D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACnC,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAS,EAAE;QAC9D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,WAAW,EAAE,CAAC,CAAA;QAClE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAChC,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAS,EAAE;QAC9D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC,CAAA;QAC9D,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAChC,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 GB Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "deprecation": { 5 | "severity": "warn" 6 | }, 7 | "max-line-length": [true, 300], 8 | "member-access": false, 9 | "member-ordering": [ 10 | true, 11 | { 12 | "order": [ 13 | "static-field", 14 | "instance-field", 15 | "static-method", 16 | "instance-method" 17 | ] 18 | } 19 | ], 20 | "indent": [true, "tabs"], 21 | "interface-name": false, 22 | "no-duplicate-variable": true, 23 | "no-eval": true, 24 | "no-redundant-jsdoc": true, 25 | "quotemark": [true, "single"], 26 | "semicolon": false, 27 | "templates-use-public": true, 28 | "import-spacing": true, 29 | "no-string-throw": false, 30 | "no-namespace": [false], 31 | "no-console": false, 32 | "variable-name": false, 33 | "one-line": false, 34 | "one-variable-per-declaration": false, 35 | "object-literal-sort-keys": false, 36 | "ordered-imports": false, 37 | "trailing-comma": false, 38 | "extends": ["tslint:latest", "tslint-config-prettier"], 39 | "curly": false, 40 | "no-shadowed-variable": false, 41 | "align": false 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /dist/src/tests/create.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"create.test.js","sourceRoot":"","sources":["../../../src/tests/create.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAChC,wDAAwD;AAExD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAChC,IAAI,MAAc,CAAA;IAClB,IAAI,QAAgB,CAAA;IAEpB,MAAM,CAAC,GAAS,EAAE;QACjB,MAAM,GAAG,IAAI,eAAM,CAAC;YACnB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,QAAQ,GAAG,OAAO,sBAAoB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAA;IAClD,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,sBAAsB,EAAE,GAAS,EAAE;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;YAChC,IAAI;YACJ,IAAI,EAAE,MAAM,GAAG,GAAG,QAAQ,OAAO;SACjC,CAAC,CAAA;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACnC,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,kDAAkD,EAAE,GAAS,EAAE;QACjE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;YAChC,IAAI;YACJ,IAAI,EAAE,MAAM,GAAG,GAAG,QAAQ,OAAO;SACjC,CAAC,CAAA;QACF,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAChC,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | working_directory: ~/project 4 | docker: 5 | - image: circleci/node:latest 6 | steps: 7 | - checkout 8 | - run: 9 | name: update-npm 10 | command: 'sudo npm install -g npm@latest' 11 | - restore_cache: 12 | key: dependency-cache-{{ checksum "package.json" }} 13 | - run: 14 | name: install-npm-wee 15 | command: sudo npm install 16 | - save_cache: 17 | key: dependency-cache-{{ checksum "package.json" }} 18 | paths: 19 | - ./node_modules 20 | - run: 21 | name: test 22 | command: npm run test 23 | - store_artifacts: 24 | path: test-results.xml 25 | prefix: tests 26 | - store_artifacts: 27 | path: coverage 28 | prefix: coverage 29 | - store_test_results: 30 | path: test-results.xml 31 | 32 | workflows: 33 | version: 2 34 | commit-workflow: 35 | jobs: 36 | - build 37 | schedule-workflow: 38 | triggers: 39 | - schedule: 40 | cron: "0 1 * * *" 41 | filters: 42 | branches: 43 | only: 44 | - master 45 | jobs: 46 | - build 47 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import gitorm from './src/index' 2 | 3 | export interface Config { 4 | token: string 5 | repository: string 6 | owner: string 7 | log?: boolean 8 | } 9 | 10 | export interface Find { 11 | path: string 12 | } 13 | 14 | export interface Create { 15 | data: any 16 | path: string 17 | message?: string 18 | branch?: string 19 | } 20 | 21 | export interface Update { 22 | data: any 23 | path: string 24 | message?: any 25 | } 26 | 27 | export interface Delete { 28 | path: string 29 | message?: string 30 | } 31 | 32 | export interface File { 33 | name: string 34 | path: string 35 | sha: string 36 | size: string 37 | url: string 38 | html_url: string 39 | git_url: string 40 | download_url: string 41 | type: string 42 | } 43 | 44 | export interface GitormInterface { 45 | new ({ token, repository, owner, log }: Config) 46 | connect: () => any 47 | find({ path }: Find): Promise 48 | findAll({ path }: Find): Promise 49 | create({ data, path, message, branch }: Create): Promise 50 | update({ data, path, message }: Update): Promise 51 | delete({ path, message }: Delete): Promise 52 | status: boolean 53 | } 54 | 55 | declare const Gitorm: GitormInterface 56 | 57 | export default Gitorm 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitorm", 3 | "version": "0.0.25", 4 | "description": "A simple ORM to use your Github Repositories as a Database and a Data Bucket with Node.js", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "test": "ts-mocha -p tsconfig.json src/**/*.test.ts --timeout 10000", 9 | "deploy": "git pull && vpdate && git push && npm publish --access public" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/gbkel/gitorm.git" 14 | }, 15 | "keywords": [ 16 | "database", 17 | "github", 18 | "repository", 19 | "orm", 20 | "databucket" 21 | ], 22 | "author": "“Guilherme Bromonschenkel (https://www.guilherr.me)", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/gbkel/gitorm/issues" 26 | }, 27 | "homepage": "https://github.com/gbkel/gitorm#readme", 28 | "devDependencies": { 29 | "@types/expect": "^1.20.4", 30 | "@types/mocha": "^5.2.7", 31 | "@types/node": "^12.7.8", 32 | "dotenv": "^8.1.0", 33 | "mocha": "^6.2.1", 34 | "ts-mocha": "^6.0.0", 35 | "tslint-config-prettier": "^1.18.0", 36 | "typescript": "^3.6.3", 37 | "vpdate": "^0.1.1" 38 | }, 39 | "dependencies": { 40 | "axios": "^0.19.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/connection.test.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config' 2 | import gitorm from '../index' 3 | import * as assert from 'assert' 4 | 5 | describe('=> Repository connection', () => { 6 | it('Should connect to github repository', async () => { 7 | const Gitorm = new gitorm({ 8 | token: process.env.GIT_TOKEN, 9 | repository: process.env.GIT_REPOSITORY, 10 | owner: process.env.GIT_OWNER, 11 | log: false 12 | }) 13 | 14 | await Gitorm.connect() 15 | assert.notStrictEqual(Gitorm.status, false) 16 | }) 17 | 18 | it('Should fail to connect with incorrect [owner]', async () => { 19 | const Gitorm = new gitorm({ 20 | token: process.env.GIT_TOKEN, 21 | repository: process.env.GIT_REPOSITORY, 22 | owner: 'process.env.GIT_OWNER' 23 | }) 24 | 25 | await Gitorm.connect() 26 | assert.strictEqual(Gitorm.status, false) 27 | }) 28 | 29 | it('Should fail to connect with incorrect [repository]', async () => { 30 | const Gitorm = new gitorm({ 31 | token: process.env.GIT_TOKEN, 32 | repository: 'process.env.GIT_REPOSITORY', 33 | owner: process.env.GIT_OWNER 34 | }) 35 | 36 | await Gitorm.connect() 37 | assert.strictEqual(Gitorm.status, false) 38 | }) 39 | 40 | it('Should fail to connect with incorrect [token]', async () => { 41 | const Gitorm = new gitorm({ 42 | token: 'process.env.GIT_TOKEN', 43 | repository: process.env.GIT_REPOSITORY, 44 | owner: process.env.GIT_OWNER 45 | }) 46 | 47 | await Gitorm.connect() 48 | assert.strictEqual(Gitorm.status, false) 49 | }) 50 | }) 51 | -------------------------------------------------------------------------------- /dist/src/tests/connection.test.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"connection.test.js","sourceRoot":"","sources":["../../../src/tests/connection.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAsB;AACtB,oCAA6B;AAC7B,iCAAgC;AAEhC,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,qCAAqC,EAAE,GAAS,EAAE;QACpD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;YACzB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,GAAG,EAAE,KAAK;SACV,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAS,EAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;YACzB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,uBAAuB;SAC9B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,oDAAoD,EAAE,GAAS,EAAE;QACnE,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;YACzB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;YAC5B,UAAU,EAAE,4BAA4B;YACxC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC,CAAA,CAAC,CAAA;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAS,EAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;YACzB,KAAK,EAAE,uBAAuB;YAC9B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACtC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;SAC5B,CAAC,CAAA;QAEF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;QACtB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzC,CAAC,CAAA,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} -------------------------------------------------------------------------------- /dist/src/tests/findall.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | describe('=> GET Request', () => { 16 | let Gitorm; 17 | before(() => __awaiter(void 0, void 0, void 0, function* () { 18 | Gitorm = new index_1.default({ 19 | token: process.env.GIT_TOKEN, 20 | repository: process.env.GIT_REPOSITORY, 21 | owner: process.env.GIT_OWNER 22 | }); 23 | yield Gitorm.connect(); 24 | })); 25 | it('Should get all files', () => __awaiter(void 0, void 0, void 0, function* () { 26 | const files = yield Gitorm.findAll({ path: 'src/' }); 27 | assert.notStrictEqual(files, false); 28 | })); 29 | }); 30 | //# sourceMappingURL=findall.test.js.map -------------------------------------------------------------------------------- /dist/src/tests/delete.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | const RandomNumber_1 = require("../utils/RandomNumber"); 16 | describe('=> DELETE Request', () => { 17 | let Gitorm; 18 | let fileName; 19 | before(() => __awaiter(void 0, void 0, void 0, function* () { 20 | Gitorm = new index_1.default({ 21 | token: process.env.GIT_TOKEN, 22 | repository: process.env.GIT_REPOSITORY, 23 | owner: process.env.GIT_OWNER 24 | }); 25 | yield Gitorm.connect(); 26 | fileName = `test${RandomNumber_1.default(0, 1e10)}`; 27 | })); 28 | it('Should delete a file', () => __awaiter(void 0, void 0, void 0, function* () { 29 | const data = JSON.stringify({ teste: 123 }); 30 | const file = yield Gitorm.create({ 31 | data, 32 | path: 'src/' + `${fileName}.json` 33 | }); 34 | const isFileDeleted = yield Gitorm.delete({ path: file.path }); 35 | assert.notStrictEqual(isFileDeleted, false); 36 | })); 37 | }); 38 | //# sourceMappingURL=delete.test.js.map -------------------------------------------------------------------------------- /dist/src/tests/update.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | const RandomNumber_1 = require("../utils/RandomNumber"); 16 | describe('=> PUT Request', () => { 17 | let Gitorm; 18 | let fileName; 19 | before(() => __awaiter(void 0, void 0, void 0, function* () { 20 | Gitorm = new index_1.default({ 21 | token: process.env.GIT_TOKEN, 22 | repository: process.env.GIT_REPOSITORY, 23 | owner: process.env.GIT_OWNER 24 | }); 25 | yield Gitorm.connect(); 26 | fileName = `test${RandomNumber_1.default(0, 1e10)}`; 27 | })); 28 | it('Should update a file', () => __awaiter(void 0, void 0, void 0, function* () { 29 | const data = JSON.stringify({ teste: 123 }); 30 | const file = yield Gitorm.create({ 31 | data, 32 | path: 'src/' + `${fileName}.json` 33 | }); 34 | const newData = JSON.stringify({ teste: 321 }); 35 | const updatedFile = yield Gitorm.update({ 36 | data: newData, 37 | path: file.path 38 | }); 39 | assert.notStrictEqual(updatedFile, false); 40 | })); 41 | }); 42 | //# sourceMappingURL=update.test.js.map -------------------------------------------------------------------------------- /dist/src/tests/find.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | describe('=> GET Request', () => { 16 | let Gitorm; 17 | before(() => __awaiter(void 0, void 0, void 0, function* () { 18 | Gitorm = new index_1.default({ 19 | token: process.env.GIT_TOKEN, 20 | repository: process.env.GIT_REPOSITORY, 21 | owner: process.env.GIT_OWNER 22 | }); 23 | yield Gitorm.connect(); 24 | })); 25 | it('Should get a file', () => __awaiter(void 0, void 0, void 0, function* () { 26 | const file = yield Gitorm.find({ path: 'src/' + 'index.txt' }); 27 | assert.notStrictEqual(file, false); 28 | })); 29 | it('Should fail to get file with incorrect [path]', () => __awaiter(void 0, void 0, void 0, function* () { 30 | const file = yield Gitorm.find({ path: 'src/123/' + 'index.txt' }); 31 | assert.strictEqual(file, false); 32 | })); 33 | it('Should fail to get file with incorrect [name]', () => __awaiter(void 0, void 0, void 0, function* () { 34 | const file = yield Gitorm.find({ path: 'src/' + 'index.png' }); 35 | assert.strictEqual(file, false); 36 | })); 37 | }); 38 | //# sourceMappingURL=find.test.js.map -------------------------------------------------------------------------------- /dist/src/tests/create.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | const RandomNumber_1 = require("../utils/RandomNumber"); 16 | describe('=> POST Request', () => { 17 | let Gitorm; 18 | let fileName; 19 | before(() => __awaiter(void 0, void 0, void 0, function* () { 20 | Gitorm = new index_1.default({ 21 | token: process.env.GIT_TOKEN, 22 | repository: process.env.GIT_REPOSITORY, 23 | owner: process.env.GIT_OWNER 24 | }); 25 | yield Gitorm.connect(); 26 | fileName = `test${RandomNumber_1.default(0, 1e10)}`; 27 | })); 28 | it('Should create a file', () => __awaiter(void 0, void 0, void 0, function* () { 29 | const data = JSON.stringify({ teste: 123 }); 30 | const file = yield Gitorm.create({ 31 | data, 32 | path: 'src/' + `${fileName}.json` 33 | }); 34 | assert.notStrictEqual(file, false); 35 | })); 36 | it('Should fail to create a file that already exists', () => __awaiter(void 0, void 0, void 0, function* () { 37 | const data = JSON.stringify({ teste: 123 }); 38 | const file = yield Gitorm.create({ 39 | data, 40 | path: 'src/' + `${fileName}.json` 41 | }); 42 | assert.strictEqual(file, false); 43 | })); 44 | }); 45 | //# sourceMappingURL=create.test.js.map -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gitorm 2 | 3 | [![npm version](https://img.shields.io/npm/v/gitorm.svg?style=flat-square)](https://www.npmjs.org/package/gitorm) 4 | [![install size](https://packagephobia.now.sh/badge?p=gitorm)](https://packagephobia.now.sh/result?p=gitorm) 5 | [![npm downloads](https://img.shields.io/npm/dm/gitorm.svg?style=flat-square)](http://npm-stat.com/charts.html?package=gitorm) 6 | [![CircleCI](https://circleci.com/gh/gbkel/gitorm/tree/master.svg?style=svg&circle-token=7bc6803f375b9f53b5dc1fd4e80739595caea83d)](https://circleci.com/gh/gbkel/gitorm/tree/master) 7 | 8 | A simple ORM to use your Github Repositories as a Database and a Data Bucket with Node.js 9 | 10 | ## Features 11 | 12 | - Make CRUD requests on files of your Github Repository 13 | - Use your Github Repository as a Data Bucket 14 | 15 | ## Installing 16 | 17 | ```bash 18 | $ npm install gitorm 19 | ``` 20 | 21 | ## Getting started 22 | 23 | #### gitorm(config) 24 | 25 | To use Gitorm, you'll need to generate a token with **repo** and **user** scopes on [Github Developer Settings](https://github.com/settings/tokens). 26 | 27 | ```js 28 | // Creating a connection 29 | import gitorm from 'gitorm' 30 | 31 | const Gitorm = new gitorm({ 32 | token: 'generated-token', 33 | repository: 'repo-name', 34 | owner: 'repo-owner' 35 | }) 36 | 37 | await Gitorm.connect() 38 | console.log(Gitorm.status) 39 | ``` 40 | 41 | #### gitorm.find(options) 42 | 43 | ```js 44 | // Finding a file 45 | const fileName = 'index.txt' 46 | const file = await Gitorm.find({ 47 | path: `src/${fileName}` 48 | }) 49 | ``` 50 | 51 | #### gitorm.findAll(options) 52 | 53 | ```js 54 | // Finding all files on a directory 55 | const file = await Gitorm.findAll({ 56 | path: 'src/' 57 | }) 58 | ``` 59 | 60 | #### gitorm.create(options) 61 | 62 | ```js 63 | // Creating a file 64 | const fileName = 'index.json' 65 | const fileData = { test: 123 } 66 | const file = await Gitorm.create({ 67 | data: JSON.stringify(fileData), 68 | path: `src/${fileName}` 69 | }) 70 | ``` 71 | 72 | #### gitorm.update(options) 73 | 74 | ```js 75 | // Updating a file 76 | const fileName = 'index.json' 77 | const updatedData = { test: 123 } 78 | const updatedFile = await Gitorm.update({ 79 | data: JSON.stringify(updatedData), 80 | path: `src/${fileName}` 81 | }) 82 | ``` 83 | 84 | #### gitorm.delete(options) 85 | 86 | ```js 87 | // Deleting a file 88 | const fileName = 'index.json' 89 | const file = await Gitorm.delete({ 90 | path: `src/${fileName}` 91 | }) 92 | ``` 93 | -------------------------------------------------------------------------------- /dist/src/tests/connection.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | require("dotenv/config"); 13 | const index_1 = require("../index"); 14 | const assert = require("assert"); 15 | describe('=> Repository connection', () => { 16 | it('Should connect to github repository', () => __awaiter(void 0, void 0, void 0, function* () { 17 | const Gitorm = new index_1.default({ 18 | token: process.env.GIT_TOKEN, 19 | repository: process.env.GIT_REPOSITORY, 20 | owner: process.env.GIT_OWNER, 21 | log: false 22 | }); 23 | yield Gitorm.connect(); 24 | assert.notStrictEqual(Gitorm.status, false); 25 | })); 26 | it('Should fail to connect with incorrect [owner]', () => __awaiter(void 0, void 0, void 0, function* () { 27 | const Gitorm = new index_1.default({ 28 | token: process.env.GIT_TOKEN, 29 | repository: process.env.GIT_REPOSITORY, 30 | owner: 'process.env.GIT_OWNER' 31 | }); 32 | yield Gitorm.connect(); 33 | assert.strictEqual(Gitorm.status, false); 34 | })); 35 | it('Should fail to connect with incorrect [repository]', () => __awaiter(void 0, void 0, void 0, function* () { 36 | const Gitorm = new index_1.default({ 37 | token: process.env.GIT_TOKEN, 38 | repository: 'process.env.GIT_REPOSITORY', 39 | owner: process.env.GIT_OWNER 40 | }); 41 | yield Gitorm.connect(); 42 | assert.strictEqual(Gitorm.status, false); 43 | })); 44 | it('Should fail to connect with incorrect [token]', () => __awaiter(void 0, void 0, void 0, function* () { 45 | const Gitorm = new index_1.default({ 46 | token: 'process.env.GIT_TOKEN', 47 | repository: process.env.GIT_REPOSITORY, 48 | owner: process.env.GIT_OWNER 49 | }); 50 | yield Gitorm.connect(); 51 | assert.strictEqual(Gitorm.status, false); 52 | })); 53 | }); 54 | //# sourceMappingURL=connection.test.js.map -------------------------------------------------------------------------------- /dist/src/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAA+B;AAG/B,MAAqB,MAAM;IAM1B,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,EAAU;QAC5D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QAEnB,IAAI,CAAC,GAAG,EAAE;YACT,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;gBACpB,OAAM;YACP,CAAC,CAAA;SACD;IACF,CAAC;IAEK,OAAO;;YACZ,IAAI;gBACH,MAAM,MAAM,GAAG,MAAM,aAAG,CAAC,GAAG,CAC3B,UAAU,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,EAC3C;oBACC,OAAO,EAAE;wBACR,aAAa,EAAE,QAAQ,GAAG,IAAI,CAAC,MAAM;qBACrC;i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B,MAAM,QAAQ,GAAG,MAAM,aAAG,CAAC,MAAM,CAChC,UAAU,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,WAAW,aAAa,UAAU,CAAC,IAAI,EAAE,EACvE;oBACC,IAAI,EAAE;wBACL,OAAO;wBACP,GAAG,EAAE,UAAU,CAAC,GAAG;qBACnB;oBACD,OAAO,EAAE;wBACR,aAAa,EAAE,QAAQ,GAAG,IAAI,CAAC,MAAM;qBACrC;iBACD,CACD,CAAA;gBAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;oBAAE,OAAO,KAAK,CAAA;gBAEzC,OAAO,IAAI,CAAA;aACX;YAAC,OAAO,KAAK,EAAE;gBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,OAAO,KAAK,CAAA;aACZ;QACF,CAAC;KAAA;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAA;IACpB,CAAC;CACD;AAvOD,yBAuOC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAA;AACvB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAA"} -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import Api from './modules/Api' 2 | import { Config, Find, File, Create, Update, Delete } from '../index.d' 3 | 4 | export default class Gitorm { 5 | private _token: string 6 | private _repository: string 7 | private _status: any 8 | private _owner: string 9 | 10 | constructor({ token, repository, owner, log = false }: Config) { 11 | this._token = token 12 | this._repository = repository 13 | this._owner = owner 14 | 15 | if (!log) { 16 | console.error = () => { 17 | return 18 | } 19 | } 20 | } 21 | 22 | async connect(): Promise { 23 | try { 24 | const status = await Api.get( 25 | `/repos/${this._owner}/${this._repository}`, 26 | { 27 | headers: { 28 | Authorization: 'token ' + this._token 29 | } 30 | } 31 | ) 32 | this._status = 33 | status && status.data && status.data.git_url 34 | ? status.data.git_url 35 | : false 36 | } catch (error) { 37 | this._status = false 38 | console.error(error) 39 | } 40 | } 41 | 42 | async find({ path }: Find): Promise { 43 | if (!this._status) return false 44 | 45 | try { 46 | const response = await Api.get( 47 | `/repos/${this._owner}/${this._repository}/contents/${path}`, 48 | { 49 | headers: { 50 | Authorization: 'token ' + this._token 51 | } 52 | } 53 | ) 54 | if (response.status !== 200) return false 55 | 56 | const file: File = response.data 57 | 58 | if (!file) return false 59 | 60 | return { 61 | name: file.name, 62 | path: file.path, 63 | sha: file.sha, 64 | size: file.size, 65 | url: file.url, 66 | html_url: file.html_url, 67 | git_url: file.git_url, 68 | download_url: file.download_url, 69 | type: file.type 70 | } 71 | } catch (error) { 72 | console.error(error) 73 | return false 74 | } 75 | } 76 | 77 | async findAll({ path }: Find): Promise { 78 | if (!this._status) return false 79 | 80 | try { 81 | const response = await Api.get( 82 | `/repos/${this._owner}/${this._repository}/contents/${path}`, 83 | { 84 | headers: { 85 | Authorization: 'token ' + this._token 86 | } 87 | } 88 | ) 89 | if (response.status !== 200) return false 90 | 91 | const files: File[] = response.data 92 | 93 | if (!files || files.length === 0) return false 94 | 95 | return files 96 | } catch (error) { 97 | console.error(error) 98 | return false 99 | } 100 | } 101 | 102 | async create({ 103 | data, 104 | path, 105 | message = 'Create', 106 | branch = 'master' 107 | }: Create): Promise { 108 | if (!this._status) return false 109 | 110 | try { 111 | const fileExists: boolean | File = await this.find({ path }) 112 | 113 | if (fileExists) return false 114 | 115 | const response = await Api.put( 116 | `/repos/${this._owner}/${this._repository}/contents/${path}`, 117 | { 118 | message, 119 | content: Buffer.from(data).toString('base64'), 120 | branch 121 | }, 122 | { 123 | headers: { 124 | Authorization: 'token ' + this._token 125 | } 126 | } 127 | ) 128 | 129 | if ( 130 | response.status !== 200 && 131 | response.status !== 201 && 132 | response.status !== 422 133 | ) 134 | return false 135 | 136 | const file: File = response.data.content 137 | 138 | return { 139 | name: file.name, 140 | path: file.path, 141 | sha: file.sha, 142 | size: file.size, 143 | url: file.url, 144 | html_url: file.html_url, 145 | git_url: file.git_url, 146 | download_url: file.download_url, 147 | type: file.type 148 | } 149 | } catch (error) { 150 | console.error(error) 151 | return false 152 | } 153 | } 154 | 155 | async update({ 156 | data, 157 | path, 158 | message = 'Update' 159 | }: Update): Promise { 160 | if (!this._status) return false 161 | 162 | try { 163 | const fileExists: any = await this.find({ path }) 164 | 165 | if (!fileExists) return false 166 | 167 | const response = await Api.put( 168 | `/repos/${this._owner}/${this._repository}/contents/${fileExists.path}`, 169 | { 170 | message, 171 | content: Buffer.from(data).toString('base64'), 172 | sha: fileExists.sha 173 | }, 174 | { 175 | headers: { 176 | Authorization: 'token ' + this._token 177 | } 178 | } 179 | ) 180 | 181 | if (response.status !== 200) return false 182 | 183 | const file: File = response.data.content 184 | 185 | return { 186 | name: file.name, 187 | path: file.path, 188 | sha: file.sha, 189 | size: file.size, 190 | url: file.url, 191 | html_url: file.html_url, 192 | git_url: file.git_url, 193 | download_url: file.download_url, 194 | type: file.type 195 | } 196 | } catch (error) { 197 | console.error(error) 198 | return false 199 | } 200 | } 201 | 202 | async delete({ path, message = 'Delete' }: Delete): Promise { 203 | if (!this._status) return false 204 | 205 | try { 206 | const fileExists: any = await this.find({ path }) 207 | 208 | if (!fileExists) return false 209 | 210 | const response = await Api.delete( 211 | `/repos/${this._owner}/${this._repository}/contents/${fileExists.path}`, 212 | { 213 | data: { 214 | message, 215 | sha: fileExists.sha 216 | }, 217 | headers: { 218 | Authorization: 'token ' + this._token 219 | } 220 | } 221 | ) 222 | 223 | if (response.status !== 200) return false 224 | 225 | return true 226 | } catch (error) { 227 | console.error(error) 228 | return false 229 | } 230 | } 231 | 232 | get status(): boolean { 233 | return this._status 234 | } 235 | } 236 | 237 | module.exports = Gitorm 238 | module.exports.default = Gitorm 239 | -------------------------------------------------------------------------------- /dist/src/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | Object.defineProperty(exports, "__esModule", { value: true }); 12 | const Api_1 = require("./modules/Api"); 13 | class Gitorm { 14 | constructor({ token, repository, owner, log = false }) { 15 | this._token = token; 16 | this._repository = repository; 17 | this._owner = owner; 18 | if (!log) { 19 | console.error = () => { 20 | return; 21 | }; 22 | } 23 | } 24 | connect() { 25 | return __awaiter(this, void 0, void 0, function* () { 26 | try { 27 | const status = yield Api_1.default.get(`/repos/${this._owner}/${this._repository}`, { 28 | headers: { 29 | Authorization: 'token ' + this._token 30 | } 31 | }); 32 | this._status = 33 | status && status.data && status.data.git_url 34 | ? status.data.git_url 35 | : false; 36 | } 37 | catch (error) { 38 | this._status = false; 39 | console.error(error); 40 | } 41 | }); 42 | } 43 | find({ path }) { 44 | return __awaiter(this, void 0, void 0, function* () { 45 | if (!this._status) 46 | return false; 47 | try { 48 | const response = yield Api_1.default.get(`/repos/${this._owner}/${this._repository}/contents/${path}`, { 49 | headers: { 50 | Authorization: 'token ' + this._token 51 | } 52 | }); 53 | if (response.status !== 200) 54 | return false; 55 | const file = response.data; 56 | if (!file) 57 | return false; 58 | return { 59 | name: file.name, 60 | path: file.path, 61 | sha: file.sha, 62 | size: file.size, 63 | url: file.url, 64 | html_url: file.html_url, 65 | git_url: file.git_url, 66 | download_url: file.download_url, 67 | type: file.type 68 | }; 69 | } 70 | catch (error) { 71 | console.error(error); 72 | return false; 73 | } 74 | }); 75 | } 76 | findAll({ path }) { 77 | return __awaiter(this, void 0, void 0, function* () { 78 | if (!this._status) 79 | return false; 80 | try { 81 | const response = yield Api_1.default.get(`/repos/${this._owner}/${this._repository}/contents/${path}`, { 82 | headers: { 83 | Authorization: 'token ' + this._token 84 | } 85 | }); 86 | if (response.status !== 200) 87 | return false; 88 | const files = response.data; 89 | if (!files || files.length === 0) 90 | return false; 91 | return files; 92 | } 93 | catch (error) { 94 | console.error(error); 95 | return false; 96 | } 97 | }); 98 | } 99 | create({ data, path, message = 'Create', branch = 'master' }) { 100 | return __awaiter(this, void 0, void 0, function* () { 101 | if (!this._status) 102 | return false; 103 | try { 104 | const fileExists = yield this.find({ path }); 105 | if (fileExists) 106 | return false; 107 | const response = yield Api_1.default.put(`/repos/${this._owner}/${this._repository}/contents/${path}`, { 108 | message, 109 | content: Buffer.from(data).toString('base64'), 110 | branch 111 | }, { 112 | headers: { 113 | Authorization: 'token ' + this._token 114 | } 115 | }); 116 | if (response.status !== 200 && 117 | response.status !== 201 && 118 | response.status !== 422) 119 | return false; 120 | const file = response.data.content; 121 | return { 122 | name: file.name, 123 | path: file.path, 124 | sha: file.sha, 125 | size: file.size, 126 | url: file.url, 127 | html_url: file.html_url, 128 | git_url: file.git_url, 129 | download_url: file.download_url, 130 | type: file.type 131 | }; 132 | } 133 | catch (error) { 134 | console.error(error); 135 | return false; 136 | } 137 | }); 138 | } 139 | update({ data, path, message = 'Update' }) { 140 | return __awaiter(this, void 0, void 0, function* () { 141 | if (!this._status) 142 | return false; 143 | try { 144 | const fileExists = yield this.find({ path }); 145 | if (!fileExists) 146 | return false; 147 | const response = yield Api_1.default.put(`/repos/${this._owner}/${this._repository}/contents/${fileExists.path}`, { 148 | message, 149 | content: Buffer.from(data).toString('base64'), 150 | sha: fileExists.sha 151 | }, { 152 | headers: { 153 | Authorization: 'token ' + this._token 154 | } 155 | }); 156 | if (response.status !== 200) 157 | return false; 158 | const file = response.data.content; 159 | return { 160 | name: file.name, 161 | path: file.path, 162 | sha: file.sha, 163 | size: file.size, 164 | url: file.url, 165 | html_url: file.html_url, 166 | git_url: file.git_url, 167 | download_url: file.download_url, 168 | type: file.type 169 | }; 170 | } 171 | catch (error) { 172 | console.error(error); 173 | return false; 174 | } 175 | }); 176 | } 177 | delete({ path, message = 'Delete' }) { 178 | return __awaiter(this, void 0, void 0, function* () { 179 | if (!this._status) 180 | return false; 181 | try { 182 | const fileExists = yield this.find({ path }); 183 | if (!fileExists) 184 | return false; 185 | const response = yield Api_1.default.delete(`/repos/${this._owner}/${this._repository}/contents/${fileExists.path}`, { 186 | data: { 187 | message, 188 | sha: fileExists.sha 189 | }, 190 | headers: { 191 | Authorization: 'token ' + this._token 192 | } 193 | }); 194 | if (response.status !== 200) 195 | return false; 196 | return true; 197 | } 198 | catch (error) { 199 | console.error(error); 200 | return false; 201 | } 202 | }); 203 | } 204 | get status() { 205 | return this._status; 206 | } 207 | } 208 | exports.default = Gitorm; 209 | module.exports = Gitorm; 210 | module.exports.default = Gitorm; 211 | //# sourceMappingURL=index.js.map --------------------------------------------------------------------------------