-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add query variable support * add git hash info * Revert "add git hash info" This reverts commit 630f29c. * update version * preview values in text * test update plugin.json script
- Loading branch information
1 parent
e1a159e
commit 15c756d
Showing
9 changed files
with
216 additions
and
24 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,59 @@ | ||
import json | ||
import os | ||
import subprocess | ||
import pprint | ||
from datetime import datetime | ||
|
||
timestamp = int( | ||
subprocess.check_output(["git", "show", "-s", "--format=%ct"]).decode().strip() | ||
) | ||
|
||
update_time = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d") | ||
|
||
|
||
def get_required_env_var(key_name: str, default=None): | ||
val = os.getenv(key_name, default) | ||
if val is None: | ||
raise ValueError(f"Environment variable {key_name} is not set") | ||
return val | ||
|
||
|
||
# ${{ github.repository }} | ||
repo = get_required_env_var("GITHUB_REPOSITORY") | ||
# ${{ github.sha }} | ||
sha = get_required_env_var("GITHUB_SHA") | ||
# ${{ github.run_id }} | ||
run_id = get_required_env_var("GITHUB_RUN_ID") | ||
# ${{ github.ref_name }} | ||
branch = get_required_env_var("GITHUB_REF_NAME") | ||
|
||
with open(os.path.join("src", "plugin.json")) as f: | ||
metadata = json.load(f) | ||
|
||
with open("package.json") as f: | ||
version = json.load(f)["version"] | ||
|
||
|
||
links = [ | ||
{"name": "Source", "url": f"https://github.com/{repo}"}, | ||
{ | ||
"name": "Commit", | ||
"url": f"https://github.com/{repo}/commit/{sha}", | ||
}, | ||
{ | ||
"name": "Build", | ||
"url": f"https://github.com/{repo}/actions/runs/{run_id}", | ||
}, | ||
] | ||
|
||
metadata["info"]["links"] = links | ||
if branch == "master": | ||
metadata["info"]["version"] = version | ||
else: | ||
metadata["info"]["version"] = version + "-" + sha[:7] | ||
|
||
metadata["info"]["updated"] = update_time | ||
|
||
pprint.pprint(metadata) | ||
with open(os.path.join("src", "plugin.json"), "w") as f: | ||
json.dump(metadata, f) |
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 React, { useState } from "react"; | ||
import { DEFAULT_QUERY, VariableQuery } from "../types"; | ||
import { CodeEditor, Field, InlineField, Input } from "@grafana/ui"; | ||
|
||
interface VariableQueryProps { | ||
query: VariableQuery; | ||
onChange: (query: VariableQuery, definition: string) => void; | ||
} | ||
|
||
export const VariableQueryEditor = ({ onChange, query }: VariableQueryProps) => { | ||
const [state, setState] = useState(query); | ||
|
||
const saveQuery = () => { | ||
onChange(state, `${state.collection} (${state.queryText})`); | ||
}; | ||
|
||
const handleCollectionChange = (event: React.FormEvent<HTMLInputElement>) => | ||
setState({ | ||
...state, | ||
collection: event.currentTarget.value, | ||
}); | ||
|
||
const handleQueryTextChange = (text: string) => | ||
setState({ | ||
...state, | ||
queryText: text, | ||
}); | ||
|
||
return ( | ||
<> | ||
<InlineField label="Collection" tooltip="Enter the MongoDB collection" | ||
error="Please enter the collection" invalid={!query.collection}> | ||
<Input | ||
name="collection" | ||
onBlur={saveQuery} | ||
onChange={handleCollectionChange} | ||
value={state.collection}> | ||
</Input> | ||
</InlineField> | ||
<Field label="Query Text" description="MongoDB aggregate (JSON)"> | ||
<CodeEditor width="100%" height={300} language="json" onBlur={saveQuery} | ||
value={query.queryText || DEFAULT_QUERY.queryText!} showMiniMap={false} showLineNumbers={true} | ||
onChange={handleQueryTextChange} | ||
/> | ||
</Field> | ||
</> | ||
); | ||
}; |
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
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