feat: ssh to http

better logging
This commit is contained in:
Jozef Steinhübl 2024-12-14 12:16:04 +01:00
parent f5229d52e8
commit 54c4614d5e
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
3 changed files with 46 additions and 1 deletions

View file

@ -109,7 +109,12 @@ int cli_command_push(int argc, char **argv) {
break;
}
printf("info: successfully pushed into '%s'.\n", provider->name);
if (provider->http != NULL) {
printf("info: successfully pushed into '%s' @ %s\n", provider->name,
provider->http);
} else {
printf("info: successfully pushed into '%s'.\n", provider->name);
}
}
free(branch_name);

View file

@ -5,6 +5,42 @@
#include <string.h>
#include <toml.h>
char *ssh_to_http(char *ssh) {
if (ssh == NULL)
return NULL;
if (strncmp(ssh, "git@", 4) != 0)
return NULL;
size_t len = strlen(ssh);
char *https = (char *)malloc(len + 10); // 8 for https://, 1 for /, 1 for \0
if (https == NULL)
return NULL;
strcpy(https, "https://");
char *colon = strchr(ssh + 4, ':');
if (colon == NULL) {
free(https);
return NULL;
}
size_t domain_len = colon - (ssh + 4);
strncat(https, ssh + 4, domain_len);
strcat(https, "/");
char *path = colon + 1;
char *git_ext = strstr(path, ".git");
if (git_ext != NULL) {
*git_ext = '\0';
}
strcat(https, path);
return https;
}
struct gimi_config *config_read() {
FILE *file_ptr;
char errbuf[200];
@ -46,6 +82,8 @@ struct gimi_config *config_read() {
toml_datum_t ssh = toml_string_in(toml_provider, "ssh");
provider->ssh = strdup(ssh.u.s);
provider->http = ssh_to_http(provider->ssh);
toml_datum_t toml_primary = toml_bool_in(toml_provider, "primary");
if (!toml_primary.ok) {
provider->primary = 0;
@ -91,6 +129,7 @@ void config_free(struct gimi_config *cfg) {
for (int i = 0; i < cfg->providers_size; i++) {
free(cfg->providers[i]->name);
free(cfg->providers[i]->ssh);
free(cfg->providers[i]->http);
}
free(cfg->providers);

View file

@ -12,6 +12,7 @@
struct gimi_config_provider {
char *name;
char *ssh;
char *http;
bool primary;
};