Skip to content

Commit

Permalink
stand up template generator (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandowns authored Feb 23, 2022
1 parent 4694b37 commit e32b8ac
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _testmain.go

cmd/gen-release-notes/bin/*
cmd/backport/bin/*
cmd/standup/bin/*

data/*

Expand All @@ -40,4 +41,4 @@ data/*

.DS_Store

.vscode
.vscode
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: gen-release-notes backport
all: gen-release-notes backport standup

.PHONY: gen-release-notes
gen-release-notes:
Expand All @@ -8,3 +8,7 @@ gen-release-notes:
.PHONY: backport
backport:
cd cmd/$@ && $(MAKE)

.PHONY: standup
standup:
cd cmd/$@ && $(MAKE)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ docker run --rm -it --env GITHUB_TOKEN=<TOKEN> rancher/ecm-distro-tools weekly_r
docker run --rm -it --env GITHUB_TOKEN=<TOKEN> rancher/ecm-distro-tools weekly_report -r rke2
```

### Daily Standup Template Generator

Send template output to standard out.

```sh
docker run --rm -it rancher/ecm-distro-tools standup
```

Send template output to a file at `${PWD}`. File will be named `YYYY-MM-dd`

```sh
docker run --rm -it rancher/ecm-distro-tools standup -f
```

## Contributing

We welcome additions to this repo and are excited to keep expanding its functionality.
Expand Down
7 changes: 0 additions & 7 deletions cmd/backport/Dockerfile

This file was deleted.

7 changes: 0 additions & 7 deletions cmd/gen-release-notes/Dockerfile

This file was deleted.

41 changes: 41 additions & 0 deletions cmd/standup/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
VERSION := v0.1.0
BINDIR := bin
BINARY := standup
override LDFLAGS +=
override CFLAGS += -static -Dbin_name=$(BINARY) -Dstandup_version=$(VERSION) -Dgit_sha=$(shell git rev-parse HEAD) -O3

PREFIX = /usr/local

UNAME_S = $(shell uname -s)

MACOS_MANPAGE_LOC = /usr/share/man
LINUX_MAPPAGE_LOC = $(PREFIX)/man/man8

$(BINDIR)/$(BINARY): $(BINDIR) clean
ifeq ($(UNAME_S),FreeBSD)
$(CC) main.c $(CFLAGS) -o $@ $(LDFLAGS) -I$(PREFIX)/include -L$(PREFIX)/lib
else
$(CC) main.c $(CFLAGS) -o $@ $(LDFLAGS)
endif

$(BINDIR):
mkdir -p $@

$(DEPDIR):
mkdir -p $@

.PHONY: install
install: $(BINDIR)/$(BINARY)
mkdir -p $(PREFIX)/bin
cp $(BINDIR)/$(BINARY) $(PREFIX)/bin

.PHONY: uninstall
uninstall:
rm -f $(PREFIX)/$(BINDIR)/$(BINARY)

.PHONY: deps
deps: $(DEPDIR)

.PHONY: clean
clean:
rm -f $(BINDIR)/*
84 changes: 84 additions & 0 deletions cmd/standup/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#define STR1(x) #x
#define STR(x) STR1(x)

// USAGE contains the application usage.
#define USAGE \
"usage: %s [-vh] [-f]\n\
-v version\n\
-h help\n\
-f create a new file. default name: yyyy-mm-dd\n"

// STANDUP_TEMPLATE contains the base information to be filled out with
// today's and tomorrow's dates. This is then ready to be used to be
// further fleshed out.
#define STANDUP_TEMPLATE \
"Yesterday:\n\
* \n\n\
Today:\n\
* \n\n\
PRs:\n\
* \n\n"

#define DATE_BUF_SZ 11

// date_format for getting the year, month, and day in yyyy-mm-dd format.
static const char* date_format = "%lu-%02lu-%02lu";

int
main(int argc, char **argv)
{
int file_output = 0;
FILE *out;

int c;
if (argc > 1) {
while ((c = getopt(argc, argv, "hvf")) != -1) {
switch (c) {
case 'h':
printf(USAGE, STR(bin_name));
return 0;
case 'v':
printf("%s %s - git: %s\n",
STR(bin_name),
STR(standup_version),
STR(git_sha));
return 0;
case 'f':
file_output = 1;
break;
default:
printf(USAGE, STR(bin_name));
return 1;
}
}
}

time_t s = time(NULL);
struct tm *now = localtime(&s);

int year = now->tm_year + 1900;
int month = now->tm_mon + 1;

char today[DATE_BUF_SZ];
sprintf(today, date_format, year, month, now->tm_mday);

// check if the output needs to be written to a file. If so, set the output
// to the file descriptor derived from "today's" date, otherwise set it to
// STDOUT.
if (file_output) {
out = fopen(today, "w");
} else {
out = stdout;
}

fprintf(out, STANDUP_TEMPLATE);
fclose(out);

return 0;
}

0 comments on commit e32b8ac

Please sign in to comment.