Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect git information #15

Open
AdrianMrn opened this issue Jan 22, 2020 · 0 comments
Open

Collect git information #15

AdrianMrn opened this issue Jan 22, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@AdrianMrn
Copy link
Collaborator

We don't want to compile this information into the build to be sent in context. Instead, we want it to be sent along with the sourcemap to the backend.

import { execSync } from 'child_process';

type GitInfo = {
    hash: string;
    message: string;
    tag: string;
    remote: string;
    isDirty: boolean;
};

function clCommand(command: string) {
    try {
        return execSync(command, { cwd: __dirname, encoding: 'utf8' }).replace('\n', '');
    } catch (error) {
        return '';
    }
}

export function getGitInfo(path: string): GitInfo {
    return <GitInfo>{
        hash: clCommand(`git -C ${path} log --pretty=format:'%H' -n 1`),
        message: clCommand(`git -C ${path} log --pretty=format:'%s' -n 1`),
        tag: clCommand(`git -C ${path} describe --tags --abbrev=0`),
        remote: clCommand(`git -C ${path} config --get remote.origin.url`),
        isDirty: !!clCommand(`git -C ${path} status -s`),
    };
}
@AdrianMrn AdrianMrn added the enhancement New feature or request label Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant