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

Supports local issue association with branches #3871

Conversation

axosoft-ramint
Copy link
Contributor

@axosoft-ramint axosoft-ramint commented Dec 16, 2024

Closes #3870

In this PR:

  • Adds models and util fns to get, add, remove or clear associated issues from branches in git config
  • Plumbs git config associated issues through to the home view branch cards. Uses as primary source with autolinks as secondary source for associated branch issues
  • Associates an issue with a branch when created through Start Work
  • Deletes all issue associations in git config when a branch is deleted through our command

In the next PR:

  • Split out issue list into its own command from Start Work
  • Add a command to branches to "associate issue with branch"

@axosoft-ramint axosoft-ramint added area-home Issues or features related to Home area-integrations Issues or features related to integrations feature New feature or request labels Dec 16, 2024
Copy link
Member

@eamodio eamodio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, but good after those are fixed up.

Though this should target the feature\home-remodeling branch rather than main

@@ -61,6 +66,7 @@ interface CreateState {
suggestNameOnly?: boolean;
suggestRepoOnly?: boolean;
confirmOptions?: CreateFlags[];
withIssue?: IssueShape;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
withIssue?: IssueShape;
associateWithIssue?: IssueShape;

Comment on lines 439 to 442
const branch = await state.repo.git.getBranch(state.name);
// TODO: These descriptors are hacked in. Use an integration function to get the right resource for the issue.
const resource = issue.repository
? {
key: `${issue.repository.owner}/${issue.repository.repo}`,
owner: issue.repository.owner,
name: issue.repository.repo,
}
: issue.project
? { key: issue.project.resourceId, id: issue.project.resourceId, name: issue.project.resourceId }
: undefined;
if (branch != null && resource != null) {
await addAssociatedIssueToBranch(this.container, branch, { ...issue, type: 'issue' }, resource);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might suggest just wrapping this completely in a function that can be reused elsewhere

src/commands/git/branch.ts Outdated Show resolved Hide resolved
return { value: undefined, paused: false };
}

if (options?.cancellation?.isCancellationRequested) return { value: undefined, paused: false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this line because there is no await so this can't change here

Comment on lines 208 to 255
return pauseOnCancelOrTimeout(
(async () => {
const output = [];
for (const issueDecoded of associatedIssues) {
try {
const issue = await getIssueFromGitConfigEntityIdentifier(container, issueDecoded);
if (issue != null) {
output.push(issue);
}
} catch (ex) {
Logger.error(ex, 'getAssociatedIssuesForBranch');
}
}
return output;
})(),
options?.cancellation,
options?.timeout,
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will happen serially which is fine at this point, but we probably want to make this parallel for the future

const associatedIssues: GitConfigEntityIdentifier[] = associatedIssuesEncoded
? (JSON.parse(associatedIssuesEncoded) as GitConfigEntityIdentifier[])
: [];
if (options?.cancellation?.isCancellationRequested || associatedIssues.some(i => i.entityId === issue.nodeId)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need options?.cancellation?.isCancellationRequested ||

let associatedIssues: GitConfigEntityIdentifier[] = associatedIssuesEncoded
? (JSON.parse(associatedIssuesEncoded) as GitConfigEntityIdentifier[])
: [];
if (options?.cancellation?.isCancellationRequested) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded

Comment on lines 143 to 144
'searchId' in entity &&
entity.searchId != null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated to check for the metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Comment on lines 151 to 167
if (!isGitConfigEntityIdentifier(decoded)) {
throw new Error('Invalid issue or pull request');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we should throw here -- could debugger; but at runtime I think we just want to move on right?

decoded.provider === EntityIdentifierProviderType.Jira &&
(decoded.resourceId == null || decoded.projectId == null)
) {
throw new Error('Invalid Jira issue');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

@axosoft-ramint axosoft-ramint force-pushed the feature/3870-associate-issues-with-branches branch from 0eeb7a1 to fa4bfe2 Compare December 17, 2024 22:34
@axosoft-ramint axosoft-ramint changed the base branch from main to feature/home-remodeling December 17, 2024 22:34
@axosoft-ramint axosoft-ramint force-pushed the feature/3870-associate-issues-with-branches branch from fa4bfe2 to c72febb Compare December 17, 2024 23:54
@axosoft-ramint axosoft-ramint merged commit a786544 into feature/home-remodeling Dec 17, 2024
@axosoft-ramint axosoft-ramint deleted the feature/3870-associate-issues-with-branches branch December 17, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-home Issues or features related to Home area-integrations Issues or features related to integrations feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support association of issues with branches outside of autolinks
2 participants