Skip to content

Commit

Permalink
fix: support repository urls ending with .git
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeessen committed Jul 5, 2024
1 parent 2e2ec41 commit 2fdb94e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2022 - 2023 dv4all
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center)
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Felix Mühlbauer (GFZ) <felix.muehlbauer@gfz-potsdam.de>
Expand Down Expand Up @@ -29,7 +30,7 @@ export default function SoftwareLinksInfo({reorderedCategories}: SoftwareLinksIn
On this page you can provide links and metadata to better describe your software. Some of this metadata can be imported automatically.

<p className="py-2"><strong>Software URLs</strong></p>
<p>Providing the URL of the source code repository of the software allows the RSD show a link to the source code on the software page, and automatically harvest information about the development activity.</p>
<p>Providing the URL of the source code repository of the software allows the RSD show a link to the source code on the software page, and automatically harvest information about the development activity. The RSD supports https URLs pointing to the git repository, or to the website of the repository.</p>
<p className="py-2">The getting started URL can be used to link to a webpage describing how to install and use the software. This link will be prominently shown on the top of the software page.</p>

<p className="py-2"><strong>Software DOI</strong></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 - 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -28,13 +28,16 @@
public class GithubScraper implements GitScraper {

private final String BASE_API_URL = "https://api.github.com";
private final String organisation;
private final String repo;
public final String organisation;
public final String repo;
private static final Pattern LINK_PATTERN = Pattern.compile("<([^>]+page=(\\d+)[^>]*)>; rel=\"([^\"]+)\"");
public static final Pattern GITHUB_URL_PATTERN = Pattern.compile("^https?://github\\.com/([^\\s/]+)/([^\\s/]+)/?$");

private GithubScraper(String organisation, String repo) {
this.organisation = Objects.requireNonNull(organisation);
if (repo.endsWith(".git")) {
repo = repo.substring(0, repo.length() - 4);
}
this.repo = Objects.requireNonNull(repo);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 - 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -35,6 +35,9 @@ public class GitlabScraper implements GitScraper {
*/
public GitlabScraper(String gitLabApiUrl, String projectPath) {
this.projectPath = projectPath;
if (this.projectPath.endsWith(".git")) {
this.projectPath = this.projectPath.substring(0, this.projectPath.length() - 4);
}
this.apiUri = gitLabApiUrl + "/v4";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center
//
// SPDX-License-Identifier: Apache-2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 - 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2022 - 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2022 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -17,6 +17,7 @@ public class GithubScraperTest {

private final String githubUrlPrefix = "https://github.com/";
private final String repo = "research-software-directory/RSD-as-a-service";
private final String repoGit = "research-software-directory/RSD-as-a-service.git";
private final String repoEmpty = "cmeessen/empty";
private final String repoNonEx = "research-software-directory/does-not-exist";

Expand Down Expand Up @@ -60,4 +61,10 @@ void givenInValidGithubUrl_whenCreatingScraper_thenEmptyScraperReturned() {
Optional<GithubScraper> scraper3 = GithubScraper.create(githubUrlPrefix + "org-only/");
Assertions.assertTrue(scraper3.isEmpty());
}

@Test
void givenGitRepoUrl_whenCreatingScraper_thenRemoveGitSuffix() {
Optional<GithubScraper> scraper = GithubScraper.create(githubUrlPrefix + repoGit);
Assertions.assertEquals(repo, scraper.get().organisation + "/" + scraper.get().repo);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <e.cahen@esciencecenter.nl>
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <christian.meessen@gfz-potsdam.de>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0

Expand Down

0 comments on commit 2fdb94e

Please sign in to comment.