@dotinc/ogre-react 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/OgreGraph.tsx +29 -0
- package/git2json.tsx +53 -0
- package/index.tsx +2 -0
- package/package.json +27 -0
- package/tsconfig.json +8 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 dot Industries, Inc.
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/OgreGraph.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, {useEffect, useState} from 'react'
|
|
2
|
+
import {Gitgraph} from '@gitgraph/react'
|
|
3
|
+
import {RepositoryObject} from '@dotinc/ogre'
|
|
4
|
+
import {formatGit2Json} from './git2json'
|
|
5
|
+
|
|
6
|
+
export interface OgreGraphProps {
|
|
7
|
+
repository: RepositoryObject<any>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const OgreGraph: React.FC<OgreGraphProps> = ({repository}) => {
|
|
11
|
+
const [graphData, setGraphData] = useState<any[] | undefined>(undefined)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!graphData) {
|
|
15
|
+
const history = repository.getHistory()
|
|
16
|
+
setGraphData(formatGit2Json(history))
|
|
17
|
+
}
|
|
18
|
+
}, [repository])
|
|
19
|
+
|
|
20
|
+
return !graphData
|
|
21
|
+
? null
|
|
22
|
+
: (
|
|
23
|
+
<Gitgraph>
|
|
24
|
+
{(gitgraph) => {
|
|
25
|
+
gitgraph.import(graphData)
|
|
26
|
+
}}
|
|
27
|
+
</Gitgraph>
|
|
28
|
+
)
|
|
29
|
+
}
|
package/git2json.tsx
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {cleanAuthor, Commit, createHeadRefValue, History, isTagRef, Reference, REFS_HEAD_KEY} from '@dotinc/ogre'
|
|
2
|
+
|
|
3
|
+
const findRefs = (commit: Commit, refs: Map<string, Reference>) => {
|
|
4
|
+
const list = []
|
|
5
|
+
const headRef = refs.get(REFS_HEAD_KEY)
|
|
6
|
+
for (const [key, ref] of refs.entries()) {
|
|
7
|
+
if (ref.value === commit.hash) {
|
|
8
|
+
if (isTagRef(key)) {
|
|
9
|
+
list.push(`tag: ${ref.name}`)
|
|
10
|
+
} else {
|
|
11
|
+
list.push(ref.name)
|
|
12
|
+
}
|
|
13
|
+
// also check if HEAD is pointing to this ref
|
|
14
|
+
if (headRef && headRef.value === createHeadRefValue(key)) {
|
|
15
|
+
list.push(headRef.name)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return list
|
|
20
|
+
}
|
|
21
|
+
// format
|
|
22
|
+
export const formatGit2Json = (history: History) => {
|
|
23
|
+
const {commits, refs} = history
|
|
24
|
+
return commits.reverse().map(c => {
|
|
25
|
+
const [name, email] = cleanAuthor(c.author)
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
'refs': findRefs(c, refs),
|
|
29
|
+
'hash': c.hash,
|
|
30
|
+
'hashAbbrev': c.hash.substring(0, 8),
|
|
31
|
+
'tree': c.tree,
|
|
32
|
+
'treeAbbrev': c.tree.substring(0, 8),
|
|
33
|
+
// FIXME there is only one parent at the moment on ogre
|
|
34
|
+
'parents': c.parent ? [c.parent] : [],
|
|
35
|
+
'parentsAbbrev': c.parent ? [c.parent.substring(0, 8)] : [],
|
|
36
|
+
committer: {
|
|
37
|
+
name,
|
|
38
|
+
email,
|
|
39
|
+
date: c.timestamp.getMilliseconds()
|
|
40
|
+
},
|
|
41
|
+
author: {
|
|
42
|
+
name,
|
|
43
|
+
email,
|
|
44
|
+
timestamp: c.timestamp.getMilliseconds()
|
|
45
|
+
},
|
|
46
|
+
'subject': c.message,
|
|
47
|
+
'body': '',
|
|
48
|
+
'notes': '',
|
|
49
|
+
// MAYBE? map changes to {additions: number, deletions: number, file: string}
|
|
50
|
+
'stats': []
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
package/index.tsx
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotinc/ogre-react",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"main": "./index.tsx",
|
|
5
|
+
"types": "./index.tsx",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dotindustries/ogre.git"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@dotinc/ogre": "^0.2.0",
|
|
13
|
+
"@gitgraph/react": "^1.6.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/react": "^17.0.39",
|
|
17
|
+
"@types/react-dom": "^17.0.13",
|
|
18
|
+
"config": "^0.1.1",
|
|
19
|
+
"tsconfig": "^0.1.1",
|
|
20
|
+
"typescript": "^4.5.3"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/",
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"gitHead": "df481b3cb9b0e16853561759ea26c44c3e268286"
|
|
27
|
+
}
|