You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "mbien (via GitHub)" <gi...@apache.org> on 2024/03/10 06:53:59 UTC
[PR] Add default Git Hyperlink Provider. [netbeans]
mbien opened a new pull request, #7147:
URL: https://github.com/apache/netbeans/pull/7147
matches PR/issue IDs and links them to the fitting web page.
This will work as long no task repository is defined under services, since those would have higher priority.
screenshot:

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528376925
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
I've no idea, but given there are already two people who've looked at this say we do it ... :shrug:
> for push I use the full URL - I know this is not common but this is done to avoid mistakes,
Yes, absolutely! Should be more common. First thing I do after adding any upstream remote is `git remote set-url --push upstream DISABLED`. Then use the full URL when absolutely required.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528382348
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
link me an example project please, ideally one which has issues in their history ;)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1529498406
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
Review Comment:
I meant... this is not my repository so I would follow the existing code :)
Did you try to check the existing code? `static final Pattern` (although I guess some cases are lowercase.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien merged PR #7147:
URL: https://github.com/apache/netbeans/pull/7147
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528451160
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
Review Comment:
Nitpick: I would use `IDS`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528320195
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
(I have origin pointed at the root repo for pull, for push I use the full URL - I know this is not common but this is done to avoid mistakes, e.g I just pushed with
```
git push -f git@github.com:mbien/netbeans nb-upgrade-module-cleanup:nb-upgrade-module-cleanup
```
everything is in that line and it will always work no matter how the repo is set up or what shell I have open)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528285754
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
At a later time (if anyone bothers to ask) we could add an option to add hostnames for systems to be treated as gitlab. My observation is, that it is not that hard to setup gitlab for local usage and thus is likely to be found in the wild.
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
Out of curiosity - is there really a pattern to name remotes "origin/whatever"? I knew that pattern from branch names, but not for remotes. I see no problem though.
Another thing I'm wondering is how to handle this case: On github I normally clone a repository I want to contribute to, then I create a local clone. At this point `origin` points to my repository. I then add a second remote `upstream`, that points to original repository. The issues I'm interested to are referred to by the url behind `upstream`, not the ones behind `origin`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528362621
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
Well, I'm working with upstream native code that uses `gitlab.freedesktop.org`. Which makes me wonder how many people who do that put `gitlab` in the host? What about checking with `uri.getHost().contains("gitlab")`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#issuecomment-2003752346
incorporated reviewer comments:
- all gitlab hosts should work now, tested with https://gitlab.freedesktop.org/pipewire/pipewire
- root repo is found by probing remotes in this order: `origin4nb`, `upstream`, `origin`, `origin/HEAD` and then anything starting with `origin/`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528332732
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
@neilcsmith-ne @matthiasblaesing how common is `upstream`?
should I do this order:
`origin4nb`
`upstream`
`origin`
`origin/*`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528457919
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin =
+ remotes.getOrDefault("origin4nb",
+ remotes.getOrDefault("upstream",
+ remotes.getOrDefault("origin",
+ remotes.getOrDefault("origin/HEAD",
+ remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst()
+ .orElse(null)
+ ))));
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
Review Comment:
Nitpick: Does `4` mean `".git".length()`?
Add white spaces around `-`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528309741
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
Yes, almost all the projects I'm working on, including all NetBeans' ones, are set up locally like this for me too - `origin` as my fork, `upstream` as original repository (and, off-topic, with push disabled on upstream).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#issuecomment-2003930389
@junichi11 ok to merge?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528332732
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
@neilcsmith-net how common is `upstream`?
should I do this order:
`origin4nb`
`upstream`
`origin`
`origin/*`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528332732
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
@neilcsmith-net @matthiasblaesing how common is `upstream`?
should I do this order:
`origin4nb`
`upstream`
`origin`
`origin/*`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528460089
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin =
+ remotes.getOrDefault("origin4nb",
+ remotes.getOrDefault("upstream",
+ remotes.getOrDefault("origin",
+ remotes.getOrDefault("origin/HEAD",
+ remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst()
+ .orElse(null)
+ ))));
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
Review Comment:
yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528320195
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
(I have origin pointed at the root repo for pull, for push I use the full URL - I know this is not common but this is done to avoid mistakes, e.g I just pushed with
```
git push -f git@github.com:mbien/netbeans nb-upgrade-module-cleanup:nb-upgrade-module-cleanup
```
everything is in that line and it will always work no matter how the repo is set up)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528320195
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
(I have origin pointed at the root repo for pull, for push I use the full URL - I know this is not common but this is done to avoid mistakes, e.g I just pushed with `git push -f git@github.com:mbien/netbeans nb-upgrade-module-cleanup:nb-upgrade-module-cleanup` - everything is in that line and it will always work no matter how the repo is set up)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528394255
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
nevermind, i found one on first attempt
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528469322
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
Review Comment:
final is so common these days that I personally only use capital case when its also public and a String or something like that. Some variables also change from final to non final and its always weird to have to rename them - at some point I used capital case less and haven't looked back.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1529626813
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+})
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin =
+ remotes.getOrDefault("origin4nb",
+ remotes.getOrDefault("upstream",
+ remotes.getOrDefault("origin",
+ remotes.getOrDefault("origin/HEAD",
+ remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst()
+ .orElse(null)
+ ))));
Review Comment:
I just looked through the code again this morning with a fresh mind and even though this is fairly compact, it isn't ideal.
the `default` part is always evaluated since its not a lambda. I am going to move the stream out of the tree into a separate `if origin==null` check.
only a minor change, going to merge after that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528315635
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
yes I agree. I actually tried to find other hosts but those two seem to be the most common ones. I have no bitbucket account so I don't know how those projects work.
Extending this is super easy though. Community can add more branches.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528312484
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
Review Comment:
I am actually not sure, I tested a few projects and the maven repo had for example:
```
$ git branch -r
origin/HEAD -> origin/master
origin/MNG-4463
origin/MNG-4645
```
I had the same thought - what if someone uses origin differently. How about adding a well known origin name which is used just as a marker for NB?
e.g: `nb-origin`? If NB sees this it uses it instead of `origin`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528382348
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
link me an example project first, ideally one which has issues in their history ;)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#issuecomment-2005651421
going to merge so that I can easier test interactions with a rebased #7128
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528394255
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin = remotes.get("origin");
+ if (origin == null) {
+ origin = remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst().orElse(null);
+ }
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ String page = null;
+ if (uri.getHost().equals("github.com")) {
+ page = "/pull/" + id; // url works for issues too
+ } else if (uri.getHost().equals("gitlab.com")) {
+ page = "/-/issues/" + id; // does gitlab auto link merge_requests ?
+ }
Review Comment:
nevermind, i found one on first attempt (pipewire)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528457919
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
+@ServiceProvider(service=VCSHyperlinkProvider.class, position = Integer.MAX_VALUE)
+public class DefaultGitHyperlinkProvider extends VCSHyperlinkProvider {
+
+ private static final Pattern ids = Pattern.compile("#[0-9]+");
+
+ @Override
+ public int[] getSpans(String text) {
+ return ids.matcher(text).results()
+ .flatMapToInt(r -> IntStream.of(r.start(), r.end()))
+ .toArray();
+ }
+
+ @Override
+ public String getTooltip(String text, int offsetStart, int offsetEnd) {
+ return Bundle.TT_DefaultGitHyperlinkProvider_link(text.substring(offsetStart, offsetEnd));
+ }
+
+ @Override
+ public void onClick(File file, String text, int offsetStart, int offsetEnd) {
+ Path path = file.toPath();
+ while (!Files.isDirectory(path) || Files.notExists(path.resolve(".git"))) {
+ path = path.getParent();
+ if (path == null) {
+ return;
+ }
+ }
+ Path repo = path;
+ RequestProcessor.getDefault().post(() -> {
+ openIssue(repo, text.substring(offsetStart + 1, offsetEnd));
+ });
+ }
+
+ private static void openIssue(Path repo, String id) {
+ try (GitClient client = GitRepository.getInstance(repo.toFile()).createClient()) {
+ Map<String, GitRemoteConfig> remotes = client.getRemotes(new DefaultProgressMonitor());
+ GitRemoteConfig origin =
+ remotes.getOrDefault("origin4nb",
+ remotes.getOrDefault("upstream",
+ remotes.getOrDefault("origin",
+ remotes.getOrDefault("origin/HEAD",
+ remotes.values().stream()
+ .filter(r -> r.getRemoteName().startsWith("origin/"))
+ .findFirst()
+ .orElse(null)
+ ))));
+ if (origin != null) {
+ for (String str : origin.getUris()) {
+ GitURI uri = new GitURI(str);
+ String path = uri.getPath().substring(0, uri.getPath().length()-4); // remove .git postfix
Review Comment:
Does `4` mean `".git".length()`?
Add white spaces around `-`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528449871
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
Review Comment:
Remove a white space?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Add default Git Hyperlink Provider. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #7147:
URL: https://github.com/apache/netbeans/pull/7147#discussion_r1528451428
##########
ide/git/src/org/netbeans/modules/git/ui/history/DefaultGitHyperlinkProvider.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.netbeans.modules.git.ui.history;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.IntStream;
+import org.netbeans.libs.git.GitClient;
+import org.netbeans.libs.git.GitException;
+import org.netbeans.libs.git.GitRemoteConfig;
+import org.netbeans.libs.git.GitRepository;
+import org.netbeans.libs.git.GitURI;
+import org.netbeans.libs.git.progress.ProgressMonitor.DefaultProgressMonitor;
+import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
+import org.openide.awt.StatusDisplayer;
+import org.openide.util.Exceptions;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Looks for '#123' patterns in text (e.g commit messages) and tries to link
+ * them to a fitting web page.
+ *
+ * <p>The repository host is identified by inspecting the registered remotes
+ * of the local git repository.
+ *
+ * @author mbien
+ */
+@Messages({
+ "# {0} - issue ID",
+ "TT_DefaultGitHyperlinkProvider.link=Click to open {0} in Browser",
+ "MSG_DefaultGitHyperlinkProvider.link.failed=Could not resolve issue link."
+ })
Review Comment:
good eyes, will do ;)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists