Skip to content

Commit

Permalink
Correct the URLs for github and gitlab
Browse files Browse the repository at this point in the history
Previously, these functions assumed the commit was in the ports tree. Now they
use the incoming $path variable. This value is taken from the FreshPorts
database and reflect the location with the source tree as stored in FreshPorts.

The code translates this value to the values used by GitHub and GitLab
respectively.

This fixes #392
  • Loading branch information
dlangille committed Oct 14, 2023
1 parent 3e9d305 commit 1757a16
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions include/freshports.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,53 @@ function freshports_git_commit_Link_freebsd($revision, $hostname, $path) {
}

function freshports_git_commit_Link_github($revision, $hostname, $path) {
return '<a href="https://github.com/FreeBSD/freebsd-ports/commit/' . htmlentities($revision) . '">' . freshports_GitHub_Icon('commit hash:' . $revision) . '</a>';
$url = 'https://github.com/FreeBSD/';

switch ($path) {
case '/ports':
$url .= 'freebsd-ports';
break;

case '/doc':
$url .= 'freebsd-doc';
break;

case '/src':
$url .= 'freebsd-src';
break;

default:
$url .= 'UNKOWN_PATH';
break;
}

$url .= '/commit/' . htmlentities($revision);
return '<a href="' . $url. '">' . freshports_GitHub_Icon('commit hash:' . $revision) . '</a>';
}

function freshports_git_commit_Link_gitlab($revision, $hostname, $path) {
return '<a href="https://gitlab.com/FreeBSD/freebsd-ports/-/commit/' . htmlentities($revision) . '">' . freshports_GitLab_Icon('commit hash:' . $revision) . '</a>';
$url = 'https://gitlab.com/FreeBSD/';

switch ($path) {
case '/ports':
$url .= 'freebsd-ports';
break;

case '/doc':
$url .= 'freebsd-doc';
break;

case '/src':
$url .= 'freebsd-src';
break;

default:
$url .= 'UNKOWN_PATH';
break;
}

$url .= '/commit/' . htmlentities($revision);
return '<a href="' . $url . '">' . freshports_GitLab_Icon('commit hash:' . $revision) . '</a>';
}

function freshports_git_commit_Link_codeberg($revision, $hostname, $path) {
Expand Down

0 comments on commit 1757a16

Please sign in to comment.