mirror of
https://github.com/xHyroM/gimi.git
synced 2025-01-04 18:38:19 +01:00
feat: ssh to http
better logging
This commit is contained in:
parent
f5229d52e8
commit
54c4614d5e
3 changed files with 46 additions and 1 deletions
|
@ -109,7 +109,12 @@ int cli_command_push(int argc, char **argv) {
|
||||||
break;
|
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);
|
free(branch_name);
|
||||||
|
|
39
src/config.c
39
src/config.c
|
@ -5,6 +5,42 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <toml.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() {
|
struct gimi_config *config_read() {
|
||||||
FILE *file_ptr;
|
FILE *file_ptr;
|
||||||
char errbuf[200];
|
char errbuf[200];
|
||||||
|
@ -46,6 +82,8 @@ struct gimi_config *config_read() {
|
||||||
toml_datum_t ssh = toml_string_in(toml_provider, "ssh");
|
toml_datum_t ssh = toml_string_in(toml_provider, "ssh");
|
||||||
provider->ssh = strdup(ssh.u.s);
|
provider->ssh = strdup(ssh.u.s);
|
||||||
|
|
||||||
|
provider->http = ssh_to_http(provider->ssh);
|
||||||
|
|
||||||
toml_datum_t toml_primary = toml_bool_in(toml_provider, "primary");
|
toml_datum_t toml_primary = toml_bool_in(toml_provider, "primary");
|
||||||
if (!toml_primary.ok) {
|
if (!toml_primary.ok) {
|
||||||
provider->primary = 0;
|
provider->primary = 0;
|
||||||
|
@ -91,6 +129,7 @@ void config_free(struct gimi_config *cfg) {
|
||||||
for (int i = 0; i < cfg->providers_size; i++) {
|
for (int i = 0; i < cfg->providers_size; i++) {
|
||||||
free(cfg->providers[i]->name);
|
free(cfg->providers[i]->name);
|
||||||
free(cfg->providers[i]->ssh);
|
free(cfg->providers[i]->ssh);
|
||||||
|
free(cfg->providers[i]->http);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(cfg->providers);
|
free(cfg->providers);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
struct gimi_config_provider {
|
struct gimi_config_provider {
|
||||||
char *name;
|
char *name;
|
||||||
char *ssh;
|
char *ssh;
|
||||||
|
char *http;
|
||||||
bool primary;
|
bool primary;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue