Skip to content

Commit

Permalink
feat(git): allow to get info for any branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tagoro9 committed Dec 23, 2022
1 parent 8765279 commit 86ab900
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Open extends FotingoCommand<void, OpenData> {
switchMap((pr) => from(open(pr.url))),
);
return commandData$.pipe(
switchMap(this.git.getBranchInfo),
switchMap(() => this.git.getBranchInfo()),
switchMap(this.getLocalChangesInformation),
withLatestFrom(commandData$),
switchMap(([changes, commandData]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Release extends FotingoCommand<JointRelease, ReleaseData> {

protected runCmd(commandData$: Observable<ReleaseData>): Observable<JointRelease> {
const releaseInformation$ = commandData$.pipe(
switchMap(this.git.getBranchInfo),
switchMap(() => this.git.getBranchInfo()),
withLatestFrom(commandData$),
switchMap(this.getLocalChangesInformation),
withLatestFrom(commandData$),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Review extends FotingoCommand<FotingoReview, ReviewData> {
protected runCmd(commandData$: Observable<ReviewData>): Observable<FotingoReview> {
return commandData$.pipe(
switchMap(this.git.push),
switchMap(this.git.getBranchInfo),
switchMap(() => this.git.getBranchInfo()),
withLatestFrom(commandData$),
switchMap(this.getLocalChangesInformation),
withLatestFrom(commandData$),
Expand Down
13 changes: 8 additions & 5 deletions src/git/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,20 @@ export class Git {

/**
* Get full information about the current branch (including commits and fixed issues)
* or the passed branch
*/
@boundMethod
public async getBranchInfo(): Promise<BranchInfo> {
const branchName = await this.getCurrentBranchName();
const issueId = getIssueId(this.config, branchName);
public async getBranchInfo(branchName?: string): Promise<BranchInfo> {
const branch = branchName || (await this.getCurrentBranchName());
const issueId = getIssueId(this.config, branch);
this.messenger.emit('Analyzing commit history', Emoji.MAG_RIGHT);
const commits = await this.getBranchCommitsFromMergeBase().then(this.transformCommits);
const commits = branchName
? []
: await this.getBranchCommitsFromMergeBase().then(this.transformCommits);
return {
commits,
issues: this.getIssues(commits, issueId),
name: branchName,
name: branch,
};
}

Expand Down

0 comments on commit 86ab900

Please sign in to comment.