Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
@percybolmer
percybolmer / codereview-gitcommit-TillLatest
Last active December 30, 2020 19:43
A code snippet that is rerun twice
tillLatest := false
if latestTag != nil {
if latestTag.Hash().String() == repo.ref.Hash().String() {
tillLatest = false
} else {
tillLatest = true
}
}
func isCommitToNearestTag(repo *git.Repository, commit *object.Commit, tillLatest bool) bool {
latestTag, previousTag, err := utils.GetLatestTagFromRepository(repo)
if err != nil {
log.Fatal("Couldn't get latest tag...", err)
}
if err != nil {
log.Fatal("Couldn't access tag...", err)
}
@percybolmer
percybolmer / codereview-gitcommit-newIsCommit
Created December 30, 2020 20:07
Check if a git commit is Nearest
// IsCommitNearest will check if a commit tag Hash is equal to the current repository HEAD tag
// If the Hashes matches, it will return true
func (r *Repository) IsCommitNearest(commit *object.Commit) (bool, error) {
latestTag, previousTag, err := r.GetLatestTag()
if err != nil {
return false, fmt.Errorf("%v:%w", "Couldn't get latest tag...", err)
}
if latestTag != nil {
package logcategory
// LogsByCategory - Type to hold logs by each's category
type LogsByCategory struct {
CI []string
FIX []string
REFACTOR []string
FEATURE []string
DOCS []string
OTHER []string
@percybolmer
percybolmer / codereview-gitcommit-printCategory
Created December 30, 2020 20:29
Prints to a string builder
// printCategory will output all items inside a Log slice and a title
func printCategory(output *strings.Builder, title string, logs []string) {
if len(logs) > 0 {
output.WriteString(fmt.Sprintf("\n\n## %s \n", title))
for _, item := range logs {
output.WriteString(item + "\n")
}
}
}
// GenerateMarkdown - Generate markdown output for the collected commits
func (logContainer *LogsByCategory) GenerateMarkdown() string {
var output strings.Builder
output.WriteString("# Changelog \n")
printCategory(&output, "CI Changes", logContainer.CI)
printCategory(&output, "Fixes", logContainer.FIX)
printCategory(&output, "Performance Fixes", logContainer.REFACTOR)
printCategory(&output, "Feature Fixes", logContainer.FEATURE)
printCategory(&output, "Doc Updates", logContainer.DOCS)
@percybolmer
percybolmer / codereview-gitcommit-AddcommitLog
Created December 30, 2020 20:51
A breakout of big swich from main
// AddCommitLog will take a commitHash and a commitMessage and append them to their
// apropriate Slice
func (logContainer *LogsByCategory) AddCommitLog(commitHash, commitMessage string) {
message := fmt.Sprintf("%s - %s", commitHash, normalizeCommit(commitMessage))
switch {
case strings.Contains(commitMessage, "ci:"):
logContainer.CI = append(logContainer.CI, message)
case strings.Contains(commitMessage, "fix:"):
logContainer.FIX = append(logContainer.FIX, message)
@percybolmer
percybolmer / codereview-gitcommit-NewMain
Created December 30, 2020 20:52
The complete new main function
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
@percybolmer
percybolmer / grpc-Interceptors.go
Last active August 6, 2021 11:35
gRPC Interceptor definitions
type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error)
type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error
type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error
type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error)
@percybolmer
percybolmer / pingCounter-before Streams.go
Last active August 6, 2021 11:35
A gRPC Unary Interceptor example
package interceptors
import (
"context"
"errors"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)