forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try typescript in kibana `plugin (#2)
* try typescript in kibana `plugin * compile js and ts from protobuf message
- Loading branch information
1 parent
b02d208
commit ff85675
Showing
9 changed files
with
569 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "castro"; | ||
option java_multiple_files = true; | ||
|
||
message Commit { | ||
string commit = 1; | ||
string committer = 2; | ||
string date = 3; | ||
string message= 4; | ||
repeated Entry entries = 5; | ||
} | ||
|
||
message Entry { | ||
string path = 1; | ||
string blob = 2; | ||
bool isBinary = 3; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React from "react"; | ||
import { | ||
EuiPage, | ||
EuiPageHeader, | ||
EuiTitle, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentHeader, | ||
EuiPageContentBody, | ||
EuiText, | ||
EuiDescriptionList, | ||
EuiAccordion, | ||
EuiCodeBlock, | ||
EuiSpacer | ||
} from "@elastic/eui"; | ||
import {ICommit, IEntry} from '../../../common/proto' | ||
|
||
interface MainProps { | ||
title: String, | ||
httpClient: any | ||
} | ||
|
||
interface MainState { | ||
entries: IEntry[], | ||
commitInfo: Array<{title: string, description?: string | null }> | ||
} | ||
|
||
export class Main extends React.Component<MainProps, MainState> { | ||
constructor(props: MainProps) { | ||
super(props); | ||
this.state = { | ||
commitInfo: [], | ||
entries: [] | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
/* | ||
FOR EXAMPLE PURPOSES ONLY. There are much better ways to | ||
manage state and update your UI than this. | ||
*/ | ||
const {httpClient} = this.props; | ||
httpClient.get("../api/castro/example").then((resp) => { | ||
const data: ICommit = resp.data; | ||
const commitInfo = [ | ||
{ | ||
title: "Commit", | ||
description: data.commit | ||
}, | ||
{ | ||
title: "Date", | ||
description: data.date | ||
}, | ||
{ | ||
title: "Committer", | ||
description: data.committer | ||
}, | ||
{ | ||
title: "Message", | ||
description: data.message | ||
} | ||
]; | ||
|
||
this.setState({commitInfo, entries: data.entries || []}); | ||
}); | ||
} | ||
|
||
render() { | ||
const {title} = this.props; | ||
return ( | ||
<EuiPage> | ||
<EuiPageHeader> | ||
<EuiTitle size="l"> | ||
<h1>Hello {title}!</h1> | ||
</EuiTitle> | ||
</EuiPageHeader> | ||
<EuiPageBody> | ||
<EuiPageContent> | ||
<EuiPageContentHeader> | ||
<EuiTitle> | ||
<h2>Current Commit</h2> | ||
</EuiTitle> | ||
</EuiPageContentHeader> | ||
<EuiPageContentBody> | ||
<EuiDescriptionList | ||
type="column" | ||
listItems={this.state.commitInfo} | ||
style={{maxWidth: '800px'}} | ||
/> | ||
<EuiSpacer size="xl"/> | ||
<EuiTitle> | ||
<h2>Changed files</h2> | ||
</EuiTitle> | ||
<EuiSpacer size="xs"/> | ||
{ | ||
this.state.entries.map((entry, idx) => | ||
<EuiAccordion | ||
id={"fid" + idx} | ||
key={"fid" + idx} | ||
buttonContent={entry.path} | ||
> | ||
<EuiCodeBlock language="javascript"> | ||
{entry.blob} | ||
</EuiCodeBlock> | ||
|
||
</EuiAccordion> | ||
) | ||
} | ||
</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</EuiPage> | ||
); | ||
} | ||
|
||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {TreeEntry} from "nodegit"; | ||
import * as Hapi from 'hapi'; | ||
import {Commit} from '../../common/proto' | ||
|
||
const Git = require("nodegit"); | ||
const Path = require("path"); | ||
|
||
|
||
async function getHeadCommit(): Promise<Commit> { | ||
const repodir = Path.join(__dirname, "../../../../"); | ||
|
||
const repo = await Git.Repository.open(repodir); | ||
const commit = await repo.getMasterCommit(); | ||
|
||
const result = Commit.create({ | ||
commit: commit.id().tostrS(), | ||
committer: commit.committer().toString(), | ||
message: commit.message(), | ||
date: commit.date().toLocaleDateString() | ||
}); | ||
const tree = await commit.getTree(); | ||
const walker = tree.walk(true); | ||
walker.on("entry", async (entry: TreeEntry) => { | ||
const blob = await entry.getBlob(); | ||
result.entries.push({ | ||
path: entry.path(), | ||
isBinary: blob.isBinary() === 1, | ||
blob: blob.isBinary() === 1 ? "binary" : blob.toString() | ||
}) | ||
}); | ||
walker.start(); | ||
return await (new Promise<Commit>(function (resolve, reject) { | ||
walker.on("end", () => { | ||
resolve(result) | ||
}) | ||
})); | ||
} | ||
|
||
export default function (server: Hapi.Server) { | ||
server.route({ | ||
path: '/api/castro/example', | ||
method: 'GET', | ||
handler(req: Hapi.Request, reply: any) { | ||
getHeadCommit().then((result: Commit) => reply(result)) | ||
} | ||
}) | ||
|
||
} |
Oops, something went wrong.