gioboa / jira-plugin

Jira plugin for VsCode
https://marketplace.visualstudio.com/items?itemName=gioboa.jira-plugin
MIT License
266 stars 41 forks source link

bug: wrong git branch name detection when submodules are present #132

Closed caleb15 closed 4 years ago

caleb15 commented 4 years ago

Is your feature request related to a problem? Please describe. Often I forget to set my working issue.

Describe the solution you'd like Upon workspace open or branch switch the jira extension would automatically scan the branch name for possible jira tickets (maybe using a regex like (\w+-\d+)) and if it matched a in-progress issue id for the current project than that issue would be set to in progress.

Describe alternatives you've considered I slap myself every time I forget to set the working issue until I remember. I'd prefer not to go this route for obvious reasons.

caleb15 commented 4 years ago

I tried to donate a couple euro to you but unfortunately it didn't work for some reason :(

Maybe github sponsors would work better?

Screenshot_20191031-174858

gioboa commented 4 years ago

Hi thanks for your feedback. The plugin already try to parse git branch name to change working issue. At this line the code https://github.com/gioboa/jira-plugin/blob/d0894dfbe5ab42ef9924f2da1bb4dd15140b2596/src/services/git-integration.service.ts#L154 For git sponsor I will check how to add it :+1: :smile:

gioboa commented 4 years ago

The regex catch branch named like this MYPRJ-123. Maybe we can improve the logic of matching. :+1: let me know :smile:

caleb15 commented 4 years ago

Ah, I guess this is actually a bug then. When I switch to a branch that matches a in-progress issue nothing happens. For example, DEV-551 is in progress but when I switch to a branch called DEV-551 I still have "no working issue" and I don't see any error logs in the console.

Here's how it would be parsed according to your regex:


image

It looks like your regex is good so not sure why it's not working :thinking:

caleb15 commented 4 years ago

my vscode info:

Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:33:40.634Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 5.0.0-32-generic snap

extension info:

Name: Jira Plugin
Id: gioboa.jira-plugin
Description: Manage your on-premises/cloud Jira in vscode
Version: 0.18.4
Publisher: gioboa
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=gioboa.jira-plugin
gioboa commented 4 years ago

The plugin search if there is an issue with the detected issue key.

gioboa commented 4 years ago

The fastest way to understand the problem is hack the plugin code. In this folder you have all installed extensions ~/.vscode/extensions If you open with text editor this file ~/.vscode/extensions/gioboa.jira-plugin-xx.xx.xx/out/src/services/git-integration.service.ts You can debug the code. console.log are visibile in VsCode dev tool - Help > Toggle Developer Tools parseTicket is a good method to start

gioboa commented 4 years ago

@caleb15 Did you find something?

caleb15 commented 4 years ago

Yeah, I found the problem. I have a submodule in my repository, but the code only grabs the first item from getGitRepositories, which in my case happens to be the submodule.

const [repo] = yield this.getGitRepositories();

image

The above picture is the result of this.getGitRepositories(). The first item with the longer path is a submodule of the second item.

caleb15 commented 4 years ago

I also had to set the gitIntegration setting to true - the default is false.

gioboa commented 4 years ago

:+1: Great! Do it works as expected now? Can we improve the code in some aspects?

caleb15 commented 4 years ago

It doesn't work as expected. When I am in a project with a submodule it doesn't automatically switch the ticket based on branch name for the reason explained in my comment above. :(

To fix it you would need to check the branch name of each repository returned by getGitRepositoriesinstead of just the first one. Currently you cache the current branch name so you would also have to change the cache to work per-repository.

gioboa commented 4 years ago

I will fix it, please give me an example to use for testing. Thanks. :+1:

caleb15 commented 4 years ago

Just add a submodule to your repository and delete it afterwards:

git submodule add https://github.com/<user>/<repoName> <name>

You can add any random repo as a submodule ^

git submodule update --init --recursive

https://github.blog/2016-02-01-working-with-submodules/

gioboa commented 4 years ago

I've built an alpha version to test this fix. Please have a try and give me feedback. :+1: If all it's ok I will release a new official version. :smile:

jira-plugin-0.18.5-alpha1.zip

caleb15 commented 4 years ago

Thanks! The jira extension recognizes main repo branches with a jira id now :)

It doesn't recognize branches within a submodule though. Personally speaking I don't care about branches in my submodule but eventually you might get someone reporting an issue for that FYI.

gioboa commented 4 years ago

Yes, thanks for your feedback. The plugin take always the last repo in git repositories and the last is the main branch. :+1: