Skip to content

Commit

Permalink
Merge pull request #94 from LambdaTest/stage
Browse files Browse the repository at this point in the history
Stage to main sync
  • Loading branch information
arushsaxena1998 authored Jun 3, 2024
2 parents aa9ef73 + 3507392 commit 0022acb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/smartui-cli",
"version": "3.0.9",
"version": "3.0.10",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand Down
8 changes: 6 additions & 2 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default (): Env => {
GITHUB_ACTIONS,
FIGMA_TOKEN,
LT_USERNAME,
LT_ACCESS_KEY
LT_ACCESS_KEY,
BASELINE_BRANCH,
CURRENT_BRANCH
} = process.env

return {
Expand All @@ -26,6 +28,8 @@ export default (): Env => {
GITHUB_ACTIONS,
FIGMA_TOKEN,
LT_USERNAME,
LT_ACCESS_KEY
LT_ACCESS_KEY,
BASELINE_BRANCH,
CURRENT_BRANCH,
}
}
10 changes: 6 additions & 4 deletions src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ export default (ctx: Context): Git => {
let gitInfo = JSON.parse(fs.readFileSync(ctx.env.SMARTUI_GIT_INFO_FILEPATH, 'utf-8'));

return {
branch: gitInfo.branch || '',
branch: ctx.env.CURRENT_BRANCH || gitInfo.branch || '',
commitId: gitInfo.commit_id.slice(0,6) || '',
commitMessage: gitInfo.commit_body || '',
commitAuthor: gitInfo.commit_author || '',
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : ''
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : '',
baselineBranch: ctx.env.BASELINE_BRANCH || ''
}
} else {
const splitCharacter = '<##>';
Expand All @@ -48,15 +49,16 @@ export default (ctx: Context): Git => {

// e.g. master\n or master\nv1.1\n or master\nv1.1\nv1.2\n
var branchAndTags = res[res.length-1].split('\n').filter(n => n);
var branch = branchAndTags[0];
var branch = ctx.env.CURRENT_BRANCH || branchAndTags[0];
var tags = branchAndTags.slice(1);

return {
branch: branch || '',
commitId: res[0] || '',
commitMessage: res[2] || '',
commitAuthor: res[7] || '',
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : ''
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : '',
baselineBranch: ctx.env.BASELINE_BRANCH || ''
};
}
}
3 changes: 3 additions & 0 deletions src/tasks/getGitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
return (!isGitRepo() && !ctx.env.SMARTUI_GIT_INFO_FILEPATH) ? '[SKIPPED] Fetching git repo details; not a git repo' : '';
},
task: async (ctx, task): Promise<void> => {
if (ctx.env.CURRENT_BRANCH && ctx.env.CURRENT_BRANCH.trim() === '') {
throw new Error('Error: The environment variable CURRENT_BRANCH cannot be empty.');
}
try {
ctx.git = getGitInfo(ctx);
task.output = chalk.gray(`branch: ${ctx.git.branch}, commit: ${ctx.git.commitId}, author: ${ctx.git.commitAuthor}`);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface Env {
FIGMA_TOKEN: string | undefined;
LT_USERNAME : string | undefined;
LT_ACCESS_KEY : string | undefined;
BASELINE_BRANCH: string | undefined;
CURRENT_BRANCH: string | undefined;
}

export interface Snapshot {
Expand Down Expand Up @@ -93,6 +95,7 @@ export interface Git {
commitAuthor: string;
commitMessage: string;
githubURL?: string;
baselineBranch?: string;
}

export interface Build {
Expand Down

0 comments on commit 0022acb

Please sign in to comment.