Skip to content

Commit

Permalink
get last commit hash code in current branch and show on status bar (#642
Browse files Browse the repository at this point in the history
)

* get current commit hash-code

* update regular expression match git commit hash
  • Loading branch information
yongbing-chen authored Oct 20, 2020
1 parent af5396f commit 88c5479
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ secrets.sh
es6-src/
report/
debug.log
src/git-commit-info.txt
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"scripts": {
"start": "env-cmd -f .env.electron nf start -p 3000",
"compile": "tsc",
"build": "react-scripts build",
"react-start": "react-scripts start",
"build": "git log -1 > src/git-commit-info.txt && react-scripts build",
"react-start": "git log -1 > src/git-commit-info.txt && react-scripts start",
"test": "react-scripts test --env=jsdom --silent",
"eject": "react-scripts eject",
"webpack:dev": "webpack --config ./config/webpack.dev.js",
Expand Down
23 changes: 18 additions & 5 deletions src/react/components/shell/statusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@
// Licensed under the MIT license.

import React from "react";
import { FontIcon } from "@fluentui/react";
import { constants } from "../../../common/constants";
import {FontIcon} from "@fluentui/react";
import {constants} from "../../../common/constants";
import axios from 'axios';
import "./statusBar.scss";
import { IProject } from "../../../models/applicationState";

export interface IStatusBarProps {
project: IProject;
}
interface IStatusBarState {
commitHash?: string;
}
export class StatusBar extends React.Component<IStatusBarProps, IStatusBarState> {
componentDidMount() {
const commitInfoUrl = require("../../../git-commit-info.txt");
axios.get(commitInfoUrl).then(res => {
// match the git commit hash
const commitHash = /commit ([0-9a-fA-F]{8})/.exec(res.data)[1];
this.setState({commitHash});
});
}


export class StatusBar extends React.Component<IStatusBarProps> {
// export class StatusBar extends React.Component<IStatusBarProps> {
public render() {
return (
<div className="status-bar">
Expand All @@ -29,7 +42,7 @@ export class StatusBar extends React.Component<IStatusBarProps> {
<li>
<a href="https://github.com/microsoft/OCR-Form-Tools/blob/master/CHANGELOG.md" target="blank" rel="noopener noreferrer">
<FontIcon iconName="BranchMerge" />
<span>{constants.appVersionRaw}-1f33130</span>
<span>{constants.appVersion}-{this.state?.commitHash}</span>
</a>
</li>
</ul>
Expand Down

0 comments on commit 88c5479

Please sign in to comment.