parent
ccc77a4081
commit
29620fe35a
@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
const char* project_path = convert_relative_to_full_path(extract_value_from_arg(args, ARG_PROJECT));
|
const char* project_path = convert_relative_to_full_path(extract_value_from_arg(args, ARG_PROJECT));
|
||||||
LOG_INFO("Project full path: %s", project_path);
|
LOG_INFO("Project full path: %s", project_path);
|
||||||
PlaformId project_platform_id = identify_platfrom_from_project(
|
PlatformIdList* project_platforms = identify_platfroms_from_project(
|
||||||
project_path,
|
project_path,
|
||||||
extract_value_from_arg(args, ARG_REMOTE));
|
extract_value_from_arg(args, ARG_REMOTE));
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
#include "base.h"
|
#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 <errno.h>
|
||||||
#include <sys/types.h>
|
#include <regex.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "../tools/buffer.h"
|
||||||
|
#include "../tools/alloc_wrappers.h"
|
||||||
|
#include "../tools/log.h"
|
||||||
|
|
||||||
const char* SUPPORTED_PLATFORM_NAMES[] = {
|
const char* SUPPORTED_PLATFORM_NAMES[] = {
|
||||||
"github.com",
|
"github.com",
|
||||||
"gitlab.com"
|
"gitlab.com"};
|
||||||
};
|
|
||||||
|
|
||||||
static void throw_regex_error(int errcode, const regex_t* preg, const char* str) {
|
static void throw_regex_error(int errcode, const regex_t* preg, const char* str) {
|
||||||
char regex_error_buffer[REGEX_ERROR_STR_MAX_LEN] = {0};
|
char regex_error_buffer[REGEX_ERROR_STR_MAX_LEN] = {0};
|
||||||
@ -48,8 +49,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|||||||
RegexWrapper regexes[GIT_CFG_RG_COUNT] = {
|
RegexWrapper regexes[GIT_CFG_RG_COUNT] = {
|
||||||
{.regex_pattern = config_remote_line_rg},
|
{.regex_pattern = config_remote_line_rg},
|
||||||
{.regex_pattern = GIT_CONFIG_NEXT_SECTION_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++) {
|
for (size_t i = 0; i < GIT_CFG_RG_COUNT; i++) {
|
||||||
int value = regcomp(&(regexes[i].regex_holder), regexes[i].regex_pattern, 0);
|
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);
|
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(
|
if (parse_regex_result(regexec(
|
||||||
&(regexes[GIT_CFG_RG_USER_GIVEN_REMOTE].regex_holder),
|
&(regexes[GIT_CFG_RG_USER_GIVEN_REMOTE].regex_holder),
|
||||||
lines->lines[i]->data,
|
lines->lines[i]->data,
|
||||||
0, NULL, 0))
|
0, NULL, 0))) {
|
||||||
) {
|
|
||||||
remote_section_found = true;
|
remote_section_found = true;
|
||||||
LOG_DEBUG("remote_section_found = true");
|
LOG_DEBUG("remote_section_found = true");
|
||||||
continue;
|
continue;
|
||||||
@ -107,7 +106,7 @@ static Lines* get_git_remote_urls_from_lines(Lines* lines, const char* remote) {
|
|||||||
return git_remote_urls;
|
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__);
|
LOG_DEBUG("Entering function %s", __func__);
|
||||||
if (project_path == NULL) {
|
if (project_path == NULL) {
|
||||||
LOG_ERROR_EXIT("No path supplied for project.");
|
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* 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);
|
Lines* git_remote_urls = get_git_remote_urls_from_lines(config_file_lines, remote);
|
||||||
|
|
||||||
|
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
|
// TODO: parse remote "origin url" to get platform
|
||||||
|
|
||||||
lines_free(config_file_lines);
|
lines_free(config_file_lines);
|
||||||
lines_flush(git_remote_urls);
|
lines_flush(git_remote_urls);
|
||||||
buffer_free(git_config_path_buffer);
|
buffer_free(git_config_path_buffer);
|
||||||
return PL_UNRECOGNIZED;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -15,6 +15,11 @@ typedef enum PlaformId {
|
|||||||
PL_UNRECOGNIZED
|
PL_UNRECOGNIZED
|
||||||
} PlaformId;
|
} PlaformId;
|
||||||
|
|
||||||
|
typedef struct PlatformIdList {
|
||||||
|
PlaformId* ids;
|
||||||
|
size_t size;
|
||||||
|
} PlatformIdList;
|
||||||
|
|
||||||
typedef enum GitConfigRegexes {
|
typedef enum GitConfigRegexes {
|
||||||
GIT_CFG_RG_USER_GIVEN_REMOTE,
|
GIT_CFG_RG_USER_GIVEN_REMOTE,
|
||||||
GIT_CFG_RG_NEXT_SECTION,
|
GIT_CFG_RG_NEXT_SECTION,
|
||||||
@ -29,6 +34,6 @@ typedef struct RegexWrapper {
|
|||||||
|
|
||||||
extern const char* SUPPORTED_PLATFORM_NAMES [];
|
extern const char* SUPPORTED_PLATFORM_NAMES [];
|
||||||
|
|
||||||
PlaformId identify_platfrom_from_project(const char* project_path, const char* remote);
|
PlatformIdList* identify_platfroms_from_project(const char* project_path, const char* remote);
|
||||||
|
|
||||||
#endif /*__PLATFORM_BASE_H__*/
|
#endif /*__PLATFORM_BASE_H__*/
|
||||||
Loading…
x
Reference in New Issue
Block a user