Commit eac66813 by Ryan McKinley Committed by GitHub

Toolkit: add git log info to the plugin build report (#21344)

parent f0764ced
......@@ -9,7 +9,7 @@ import { PluginMeta } from '@grafana/data';
import execa = require('execa');
import path = require('path');
import fs from 'fs';
import { getPackageDetails, findImagesInFolder, getGrafanaVersions } from '../../plugins/utils';
import { getPackageDetails, findImagesInFolder, getGrafanaVersions, readGitLog } from '../../plugins/utils';
import {
job,
getJobFolder,
......@@ -324,6 +324,7 @@ const pluginReportRunner: TaskRunner<PluginCIOptions> = async ({ upload }) => {
tests: agregateTestInfo(),
artifactsBaseURL: await getCircleDownloadBaseURL(),
grafanaVersion: getGrafanaVersions(),
git: await readGitLog(),
};
const pr = getPullRequestNumber();
if (pr) {
......
......@@ -11,6 +11,7 @@ export interface PluginBuildReport {
workflow: WorkflowInfo;
coverage: CoverageInfo[];
tests: TestResultsInfo[];
git?: GitLogInfo;
pullRequest?: number;
artifactsBaseURL?: string;
grafanaVersion?: KeyValue<string>;
......@@ -70,3 +71,19 @@ export interface ZipFileInfo {
sha1?: string;
md5?: string;
}
interface UserInfo {
name: string;
email: string;
time?: number;
}
export interface GitLogInfo {
commit: string;
tree: string;
subject: string;
body?: string;
notes?: string;
author: UserInfo;
commiter: UserInfo;
}
......@@ -2,7 +2,7 @@ import execa from 'execa';
import path from 'path';
import fs from 'fs';
import { KeyValue } from '@grafana/data';
import { ExtensionSize, ZipFileInfo } from './types';
import { ExtensionSize, ZipFileInfo, GitLogInfo } from './types';
const md5File = require('md5-file');
......@@ -92,3 +92,39 @@ export function findImagesInFolder(dir: string, prefix = '', append?: string[]):
return imgs;
}
export async function readGitLog(): Promise<GitLogInfo | undefined> {
try {
let exe = await execa('git', [
'log',
'-1', // last line
'--pretty=format:{%n "commit": "%H",%n "tree": "%T",%n "subject": "%s",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "time":"%at" },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "time":"%ct" }%n}',
]);
const info = JSON.parse(exe.stdout) as GitLogInfo;
// Read the body
exe = await execa('git', [
'log',
'-1', // last line
'--pretty=format:%b', // Just the body (with newlines!)
]);
if (exe.stdout && exe.stdout.length) {
info.body = exe.stdout.trim();
}
// Read any commit notes
exe = await execa('git', [
'log',
'-1', // last line
'--pretty=format:%N', // commit notes (with newlines!)
]);
if (exe.stdout && exe.stdout.length) {
info.notes = exe.stdout.trim();
}
return info;
} catch (err) {
console.warn('Error REading Git log info', err);
}
return undefined;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment