Skip to content

Commit 0c9b594

Browse files
nouwaaromdiasbruno
andauthored
misc: Apply suggestions from code review
Co-authored-by: Bruno Dias <[email protected]>
1 parent 4f9d33a commit 0c9b594

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/registry/github-registry.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
#include <curl/curl.h>
1919
#include <string.h>
2020

21+
#define GITHUB_BASE_URL "https://github.com/"
22+
2123
/**
2224
* Add `href` to the given `package`.
2325
*/
2426
static void add_package_href(registry_package_ptr_t self) {
2527
size_t len = strlen(self->id) + 20; // https://github.com/ \0
2628
self->href = malloc(len);
2729
if (self->href)
28-
sprintf(self->href, "https://github.com/%s", self->id);
30+
sprintf(self->href, GITHUB_BASE_URL "%s", self->id);
2931
}
3032

3133
/**
@@ -129,4 +131,3 @@ list_t *github_registry_fetch(const char *url) {
129131
http_get_free(res);
130132
return list;
131133
}
132-

src/repository/gitlab-repository.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
#include <string.h>
1111
#include <url/url.h>
1212

13+
#define GITLAB_API_V4_URL "https://%s/api/v4%s/repository/files/%s/raw?ref=master"
14+
1315
// GET :hostname/api/v4/projects/:id/repository/files/:file_path/raw
1416
char* gitlab_repository_get_url_for_file(const char*package_url, const char* slug, const char* version, const char *file, const char* secret) {
1517
url_data_t *parsed = url_parse(package_url);
1618

1719
int size = strlen(parsed->hostname) + strlen(parsed->pathname) + strlen(file) + 64;
1820
char *url = malloc(size);
1921
if (url) {
20-
snprintf(url, size, "https://%s/api/v4%s/repository/files/%s/raw?ref=master", parsed->hostname, parsed->pathname, file);
22+
snprintf(url, size, GITLAB_API_V4_URL, parsed->hostname, parsed->pathname, file);
2123
}
2224

2325
url_free(parsed);

0 commit comments

Comments
 (0)