diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-07-06 09:49:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-06 09:49:51 -0400 |
commit | 8ce824ac4b2f526331093a7150e643700efd4d20 (patch) | |
tree | 99e27dee24e82d78941ded4c510e1bac57c3f015 /src/template_func_proto.c | |
parent | abe87056faa6ed02aff3bbf77c1fd78b713a0864 (diff) | |
download | stasis-8ce824ac4b2f526331093a7150e643700efd4d20.tar.gz |
Add github.c and github.h (#9)
* Add github.c and github.h
* Implements get_github_release_notes()
* Remove unused variables
* Fix circular dependency on tplfunc_frame
* Remove predeclaration of tplfunc_frame
* tpl_register_func accepts pointer to void instead
* tpl_register_func sets maximum number of arguments
* Frame is generated within tpl_register_func
* Improve template function error handling and return/output management
* Remove redundant extern statement
* Include github.h and template_func_proto.h in core.h
* Expose get_github_release_notes_tplfunc_entrypoint function to template engine
* Add template_func_proto.c and template_func_proto.h
* Replace free() with guard variant
* Fix test_template::test_tpl_register_func
* Fix tests
* Fix tests
* cmd should be at least PATH_MAX in size.
* Magic number caused failure to install conda with a long installation path
* Implement get_github_release_notes_auto function that bases release note data off test contexts
* Disable overwriting releases by default
* Add automatic release note generation function call to release_notes.md.in
* Fix test_tpl_register_func()
* Add enough space for tar command plus a path
* Fix circular include
* Github functions do not require access to core.h anyway
* Add comments to union
* Update README to mention template function availability
* Add EnvCtl structure
* Add runtime checks to avoid running all the way to the end only to be met with a configuration error.
* Rename GITHUB to GH
* Development docs pre-rough-draft
Diffstat (limited to 'src/template_func_proto.c')
-rw-r--r-- | src/template_func_proto.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/template_func_proto.c b/src/template_func_proto.c new file mode 100644 index 0000000..140a5e0 --- /dev/null +++ b/src/template_func_proto.c @@ -0,0 +1,65 @@ +#include "template_func_proto.h" + +int get_github_release_notes_tplfunc_entrypoint(void *frame, void *data_out) { + int result; + char **output = (char **) data_out; + struct tplfunc_frame *f = (struct tplfunc_frame *) frame; + char *api_token = getenv("STASIS_GH_TOKEN"); + if (!api_token) { + api_token = getenv("GITHUB_TOKEN"); + } + result = get_github_release_notes(api_token ? api_token : "anonymous", + (const char *) f->argv[0].t_char_ptr, + (const char *) f->argv[1].t_char_ptr, + (const char *) f->argv[2].t_char_ptr, + output); + return result; +} + +int get_github_release_notes_auto_tplfunc_entrypoint(void *frame, void *data_out) { + int result = 0; + char **output = (char **) data_out; + struct tplfunc_frame *f = (struct tplfunc_frame *) frame; + char *api_token = getenv("STASIS_GITHUB_TOKEN"); + if (!api_token) { + api_token = getenv("GITHUB_TOKEN"); + } + + const struct Delivery *ctx = (struct Delivery *) f->data_in; + struct StrList *notes_list = strlist_init(); + for (size_t i = 0; i < sizeof(ctx->tests) / sizeof(*ctx->tests); i++) { + // Get test context + const struct Test *test = &ctx->tests[i]; + if (test->name && test->version && test->repository) { + char *repository = strdup(test->repository); + char *match = strstr(repository, "spacetelescope/"); + // Cull repository URL + if (match) { + replace_text(repository, "https://github.com/", "", 0); + if (endswith(repository, ".git")) { + replace_text(repository, ".git", "", 0); + } + // Record release notes for version relative to HEAD + // Using HEAD, GitHub returns the previous tag + char *note = NULL; + char h1_title[NAME_MAX] = {0}; + sprintf(h1_title, "# %s", test->name); + strlist_append(¬es_list, h1_title); + result += get_github_release_notes(api_token ? api_token : "anonymous", + repository, + test->version, + "HEAD", + ¬e); + if (note) { + strlist_append(¬es_list, note); + guard_free(note); + } + } + } + } + // Return all notes as a single string + if (strlist_count(notes_list)) { + *output = join(notes_list->data, "\n\n"); + } + return result; +} |