diff --git a/.github/img/gitstorykit.png b/.github/img/gitstorykit.png
new file mode 100644
index 0000000..8603e57
Binary files /dev/null and b/.github/img/gitstorykit.png differ
diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml
new file mode 100644
index 0000000..ef8c690
--- /dev/null
+++ b/.github/workflows/npm-publish.yml
@@ -0,0 +1,33 @@
+# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
+# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
+
+name: Node.js Package
+
+on:
+ release:
+ types: [created]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions/setup-node@v2
+ with:
+ node-version: 16
+ - run: npm ci
+ - run: npm test
+
+ publish-npm:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions/setup-node@v2
+ with:
+ node-version: 16
+ registry-url: https://registry.npmjs.org/
+ - run: npm ci
+ - run: npm publish
+ env:
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
diff --git a/README.md b/README.md
index e69de29..250bfb7 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+GitStoryKit is a little development kit that can be used to develop apps and software that enables git time travel, the library is in early development and is designed for simplicity.
+
+GitStoryKit is heavily used in GitStory
+
+The following Git clients are supported :
+- GitHub ✅
+- Gitlab ⏳ (on development)
+- BitBucket ⏳ (on development)
+
+## Usage
+
+### Initialization
+
+```js
+import GitStory from "gitstorykit";
+
+const gitstory = new GitStory("Github");
+
+gitstory.init({ owner: "vercel", repo: "next.js", sha: "5.0" });
+```
+
+### Get first commit
+```js
+const firstcommit = await gitstory.getFirstCommit();
+```
+
+### Get first commit Date
+```js
+const firstcommitdate = await gitstory.getFirstCommitDate();
+```
+
+### Get a commit's Date
+Dates should be in the **ISO 8601 format**
+```js
+const commit_date = await gitstory.getCommitDate(commit_sha);
+```
+
+### Get commit between dates
+
+Dates should be in the **ISO 8601 format**
+```js
+const commit = await gitstory.getCommitsBetweenDates(startDate, endDate, per_page: number, page: number);
+```
+
+### Get commits until date
+
+Dates should be in the **ISO 8601 format**
+```js
+const commit = await gitstory.getCommitsUntilDate(date, per_page: number, page: number);
+```
+
+### Get a repository active years
+```js
+const active_years = await gitstory.yearsActive();
+```
+
+
+
+## Contributing
+
+Please see our [contributing.md](/CONTRIBUTING.md).
+
+## Authors
+
+Badr B. ([@swve](https://github.com/swve))
diff --git a/clients/github/index.ts b/clients/github/index.ts
index 11e3f90..75777a8 100644
--- a/clients/github/index.ts
+++ b/clients/github/index.ts
@@ -1,9 +1,9 @@
-import { ParamsInterface, TimeInterface } from "../../interfaces";
+import { ParamsInterface } from "../../interfaces";
import { Octokit } from "@octokit/rest";
-import * as parse from "parse-link-header";
+import parse from "parse-link-header";
export class GithubClient {
- octokit = new Octokit();
+ private octokit = new Octokit();
private config;
init(params: ParamsInterface) {
@@ -34,7 +34,6 @@ export class GithubClient {
return firstcommit;
}
-
/**
* Get first commit date
* Dates are in ISO 8601 format
@@ -46,30 +45,46 @@ export class GithubClient {
return date;
}
+ /**
+ * Get last commit date
+ * Dates are in ISO 8601 format
+ * @param params
+ */
+ async getLastCommitDate() {
+ const commit = await this.octokit.rest.repos.listCommits({
+ per_page: 1,
+ ...this.config,
+ });
+ const date = await commit.data[0].commit.author.date;
+ return date;
+ }
+
/**
* Get a commit date
* Dates are in ISO 8601 format
- */
- async getCommitDate(commit_sha:string) {
+ */
+ async getCommitDate(commit_sha: string) {
const commit = await this.octokit.rest.git.getCommit({
commit_sha: commit_sha,
- ...this.config
+ ...this.config,
});
const date = await commit.data.author.date;
return date;
}
/**
- * Get a particular day commits
+ * Get a particular day commits
* Dates are in ISO 8601 format
- * @param params
+ * @param params
*/
- async getCommitsBetween(startDate:string,endDate:string){
+ async getCommitsBetween(startDate: string, endDate: string, per_page: number, page: number) {
const res = await this.octokit.rest.repos.listCommits({
- since:startDate,
- until:endDate,
- ...this.config
- })
+ since: startDate,
+ until: endDate,
+ per_page: per_page,
+ page: page,
+ ...this.config,
+ });
return res;
}
@@ -78,13 +93,31 @@ export class GithubClient {
* Dates are in ISO 8601 format
* @param date
*/
-
- async getCommitsUntil(date:string){
+ async getCommitsUntil(date: string, per_page: number, page: number) {
const res = await this.octokit.rest.repos.listCommits({
- until:date,
- ...this.config
- })
+ until: date,
+ per_page: per_page,
+ page: page,
+ ...this.config,
+ });
return res;
}
+ /**
+ * Get a list of a repo active years
+ * Returns an array of years
+ * @param
+ */
+ async yearsActive() {
+ const first = await this.getFirstCommitDate();
+ const last = await this.getLastCommitDate();
+ const firstYear = parseInt(first.substring(0, 4));
+ const lastYear = parseInt(last.substring(0, 4));
+
+ const years = [];
+ for (let i = firstYear; i <= lastYear; i++) {
+ years.push(i);
+ }
+ return years;
+ }
}
diff --git a/index.ts b/index.ts
index 420a2b2..5b5ec27 100644
--- a/index.ts
+++ b/index.ts
@@ -6,20 +6,21 @@ export default class GitStory {
private clientName: string;
private client;
- constructor(client) {
- this.clientName = client;
+ constructor(clientName: string) {
+ this.clientName = clientName;
}
- /**
- * Git client init
- * @param params
+ /**
+ * Git client init
+ * @param params
*/
-
+
init(params: ParamsInterface) {
switch (this.clientName.toLowerCase()) {
case "github":
this.client = new GithubClient();
this.client.init(params);
+
break;
case "gitlab":
@@ -27,8 +28,8 @@ export default class GitStory {
}
}
- /**
- * Git Functions
+ /**
+ * Git Functions
* Available Features/endpoints
*/
@@ -40,18 +41,19 @@ export default class GitStory {
return this.client.getFirstCommitDate();
}
- async getCommitDate(commit_sha){
+ async getCommitDate(commit_sha) {
return this.client.getCommitDate(commit_sha);
}
- async getCommitsBetweenDates(startDate, endDate) {
- return this.client.getCommitsBetween(startDate, endDate);
+ async getCommitsBetweenDates(startDate, endDate, per_page: number, page: number) {
+ return this.client.getCommitsBetween(startDate, endDate, per_page, page);
}
- async getCommitsUntilDate(date) {
- return this.client.getCommitsUntil(date);
+ async getCommitsUntilDate(date, per_page: number, page: number) {
+ return this.client.getCommitsUntil(date, per_page, page);
}
+ async yearsActive() {
+ return this.client.yearsActive();
+ }
}
-
-
diff --git a/interfaces.ts b/interfaces.ts
index 6d90d76..aee166a 100644
--- a/interfaces.ts
+++ b/interfaces.ts
@@ -4,12 +4,3 @@ export interface ParamsInterface {
sha: string;
token?: string;
}
-
-export interface TimeInterface {
- date: {
- years?: number;
- weeks?: number;
- months?: number;
- };
- commit?: string;
-}
diff --git a/package-lock.json b/package-lock.json
index 71eb810..39601a2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,13 +1,13 @@
{
- "name": "gitstory",
+ "name": "gitstorykit",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
- "name": "gitstory",
+ "name": "gitstorykit",
"version": "1.0.0",
- "license": "GNU GPLv3",
+ "license": "GPL-3.0-or-later",
"dependencies": {
"@octokit/rest": "^18.5.3",
"@types/parse-link-header": "^1.0.0",
diff --git a/package.json b/package.json
index 5f6f595..f3d792f 100644
--- a/package.json
+++ b/package.json
@@ -1,20 +1,21 @@
{
"name": "gitstorykit",
- "version": "1.0.0",
+ "version": "1.1.0",
"author": "swve",
- "main": "index.js",
+ "main": "dist/index.js",
+ "module": "dist/index.js",
+ "files": [
+ "dist/"
+ ],
"scripts": {
- "test": "ts-node test.ts",
- "prepublishOnly": "npm run compile",
- "compile": "npm run clean && tsc -p .",
- "watch": "tsc -w -p .",
- "clean": "rm -rf dist"
+ "test": "ts-node tests/test.ts",
+ "tsc": "tsc -p tsconfig.json",
+ "prepublish": "npm run tsc"
},
"license": "GPL-3.0-or-later",
"dependencies": {
"@octokit/rest": "^18.5.3",
"@types/parse-link-header": "^1.0.0",
- "dayjs": "^1.10.4",
"parse-link-header": "^1.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
diff --git a/tests/test.ts b/tests/test.ts
index 03a3382..17e12d4 100644
--- a/tests/test.ts
+++ b/tests/test.ts
@@ -9,14 +9,15 @@ const test3 = "2018-01-13T00:00:00.000Z";
async function testCommitUntilDate(){
- const test = await gitstory.getCommitsUntilDate(test3);
+
+ const test = await gitstory.getCommitsUntilDate(test3, 200, 1);
test.data.forEach((element) => {
console.log(element.commit.author.date);
});
}
async function testCommitBetween(){
- const test = await gitstory.getCommitsBetweenDates(start, end);
+ const test = await gitstory.getCommitsBetweenDates(start, end, 200, 1);
test.data.forEach((element) => {
console.log(element.commit.author.date);
});
@@ -27,9 +28,16 @@ async function testGetCommitDate(){
console.log(test);
}
+async function yearsActive() {
+ const test = await gitstory.yearsActive();
+ console.log(test);
+
+
+}
(async function () {
- testCommitUntilDate();
+ //testCommitUntilDate();
+ yearsActive();
//testGetCommitDate();
//testCommitBetween();
// → 🎉
diff --git a/tsconfig.json b/tsconfig.json
index 8791e46..d2bf14d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,11 +1,10 @@
{
- "compilerOptions": {
- "module": "commonjs",
- "target": "esnext",
- "declaration": true,
- "outDir": "./dist"
- },
- "include": [
- "src/**/*"
-, "tests/test.ts" ]
- }
\ No newline at end of file
+ "compilerOptions": {
+ "module": "commonjs",
+ "target": "esnext",
+ "declaration": true,
+ "esModuleInterop": true,
+ "outDir": "./dist"
+ },
+ "include": [".", "src/**/*", "tests/test.ts"]
+}