|
|
|
|
@@ -1,22 +1,23 @@
|
|
|
|
|
#include "base.h"
|
|
|
|
|
#include "../tools/buffer.h"
|
|
|
|
|
#include "../tools/log.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <regex.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <regex.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
const char* SUPPORTED_PLATFORM_NAMES [] = {
|
|
|
|
|
"github.com",
|
|
|
|
|
"gitlab.com"
|
|
|
|
|
};
|
|
|
|
|
#include "../tools/buffer.h"
|
|
|
|
|
#include "../tools/alloc_wrappers.h"
|
|
|
|
|
#include "../tools/log.h"
|
|
|
|
|
|
|
|
|
|
static void throw_regex_error(int errcode, const regex_t *preg, const char* str) {
|
|
|
|
|
const char* SUPPORTED_PLATFORM_NAMES[] = {
|
|
|
|
|
"github.com",
|
|
|
|
|
"gitlab.com"};
|
|
|
|
|
|
|
|
|
|
static void throw_regex_error(int errcode, const regex_t* preg, const char* str) {
|
|
|
|
|
char regex_error_buffer[REGEX_ERROR_STR_MAX_LEN] = {0};
|
|
|
|
|
size_t written = regerror(errcode, preg, regex_error_buffer, REGEX_ERROR_STR_MAX_LEN);
|
|
|
|
|
LOG_DEBUG("regex_error_str() errcode: %d, regerror ret: %lu", errcode, written);
|
|
|
|
|
@@ -35,7 +36,7 @@ static bool parse_regex_result(int value) {
|
|
|
|
|
|
|
|
|
|
static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|
|
|
|
LOG_DEBUG("Entering function %s", __func__);
|
|
|
|
|
char config_remote_line_rg [GIT_CONFIG_REMOTE_STRING_MAX_LEN] = {0};
|
|
|
|
|
char config_remote_line_rg[GIT_CONFIG_REMOTE_STRING_MAX_LEN] = {0};
|
|
|
|
|
const int config_remote_line_written_bytes = snprintf(
|
|
|
|
|
config_remote_line_rg,
|
|
|
|
|
GIT_CONFIG_REMOTE_STRING_MAX_LEN,
|
|
|
|
|
@@ -45,11 +46,10 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|
|
|
|
LOG_ERROR_EXIT("Failed generating remote string [remote \"value\"]. Value %s",
|
|
|
|
|
remote);
|
|
|
|
|
}
|
|
|
|
|
RegexWrapper regexes [GIT_CFG_RG_COUNT] = {
|
|
|
|
|
RegexWrapper regexes[GIT_CFG_RG_COUNT] = {
|
|
|
|
|
{.regex_pattern = config_remote_line_rg},
|
|
|
|
|
{.regex_pattern = GIT_CONFIG_NEXT_SECTION_RG},
|
|
|
|
|
{.regex_pattern = GIT_CONFIG_REMOTE_URL_RG}
|
|
|
|
|
};
|
|
|
|
|
{.regex_pattern = GIT_CONFIG_REMOTE_URL_RG}};
|
|
|
|
|
for (size_t i = 0; i < GIT_CFG_RG_COUNT; i++) {
|
|
|
|
|
int value = regcomp(&(regexes[i].regex_holder), regexes[i].regex_pattern, 0);
|
|
|
|
|
if (value != 0) throw_regex_error(value, &(regexes[i].regex_holder), regexes[i].regex_pattern);
|
|
|
|
|
@@ -92,8 +92,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|
|
|
|
if (parse_regex_result(regexec(
|
|
|
|
|
&(regexes[GIT_CFG_RG_USER_GIVEN_REMOTE].regex_holder),
|
|
|
|
|
lines->lines[i]->data,
|
|
|
|
|
0, NULL, 0))
|
|
|
|
|
) {
|
|
|
|
|
0, NULL, 0))) {
|
|
|
|
|
remote_section_found = true;
|
|
|
|
|
LOG_DEBUG("remote_section_found = true");
|
|
|
|
|
continue;
|
|
|
|
|
@@ -107,7 +106,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|
|
|
|
return git_remote_urls;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlaformId identify_platfrom_from_project(const char* project_path, const char* remote) {
|
|
|
|
|
PlatformIdList* identify_platfroms_from_project(const char* project_path, const char* remote) {
|
|
|
|
|
LOG_DEBUG("Entering function %s", __func__);
|
|
|
|
|
if (project_path == NULL) {
|
|
|
|
|
LOG_ERROR_EXIT("No path supplied for project.");
|
|
|
|
|
@@ -119,9 +118,14 @@ PlaformId identify_platfrom_from_project(const char* project_path, const char* r
|
|
|
|
|
|
|
|
|
|
Lines* config_file_lines = read_file_lines(git_config_path_buffer->data);
|
|
|
|
|
Lines* git_remote_urls = get_git_remote_urls_from_lines(config_file_lines, remote);
|
|
|
|
|
//TODO: parse remote "origin url" to get platform
|
|
|
|
|
|
|
|
|
|
PlatformIdList* platforms = cdo_calloc(1, sizeof(PlatformIdList));
|
|
|
|
|
platforms->size = git_remote_urls->size;
|
|
|
|
|
platforms->ids = cdo_malloc(platforms->size * sizeof(PlaformId));
|
|
|
|
|
// TODO: parse remote "origin url" to get platform
|
|
|
|
|
|
|
|
|
|
lines_free(config_file_lines);
|
|
|
|
|
lines_flush(git_remote_urls);
|
|
|
|
|
buffer_free(git_config_path_buffer);
|
|
|
|
|
return PL_UNRECOGNIZED;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|