Skip to content

Commit

Permalink
Add commits to release_notes feature
Browse files Browse the repository at this point in the history
Adds commits to release notes.

Tested with temporary org. Closes: #141

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Feb 6, 2020
1 parent 6a7c2cf commit 7d64f71
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM openfaas/classic-watchdog:0.18.1 as watchdog
FROM openfaas/classic-watchdog:0.18.10 as watchdog

FROM golang:1.11-alpine as build
FROM golang:1.13-alpine as build

ENV CGO_ENABLED=0
ENV GO111MODULE=off

WORKDIR /go/src/github.com/alexellis/derek
COPY . .
Expand All @@ -11,7 +12,7 @@ RUN go test $(go list ./... | grep -v /vendor/) -cover

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o derek .

FROM alpine:3.10 as ship
FROM alpine:3.11 as ship

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
Expand Down
5 changes: 3 additions & 2 deletions derek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ provider:
functions:
derek-098:
handler: ./
image: alexellis/derek:0.9.8
image: alexellis/derek:0.9.9
lang: dockerfile
environment:
debug: true
customers_url: https://raw.githubusercontent.com/alexellis/derek/master/.CUSTOMERS
validate_hmac: true
validate_customers: true
validate_customers: false
secret_path: /var/openfaas/secrets/ # use /run/secrets/ for older OpenFaaS versions
write_debug: true
read_timeout: 10s
write_timeout: 10s
combine_output: false
environment_file:
- secrets.yml
# See secrets.example.yml
Expand Down
86 changes: 69 additions & 17 deletions handler/release_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"sort"
"strings"
"time"

"github.com/alexellis/derek/config"
Expand Down Expand Up @@ -54,6 +55,72 @@ func updateReleaseNotes(client *github.Client, owner, repo, latestTag string) er

workingReleases := getWorkingReleases(releases, owner, repo, latestTag)

includedPRs, err := buildClosedPRs(client, workingReleases, owner, repo, latestTag)

if err != nil {
return err
}

includedCommits, err := buildCommits(client, workingReleases, owner, repo, latestTag)

if err != nil {
return err
}

output := fmt.Sprintf("Changelog for %s:\n", workingReleases.CurrentTag)

for _, pr := range includedPRs {
output = output + fmt.Sprintf("* PR #%d %s by @%s\n",
pr.GetNumber(),
pr.GetTitle(),
pr.GetUser().GetLogin())
}

output += fmt.Sprintf("\nCommits\n")

for _, c := range includedCommits {
id := c.GetSHA()
author := c.GetAuthor().GetLogin()
title := c.GetCommit().GetMessage()
if index := strings.Index(title, "\n"); index > -1 {
title = title[:index]
}

output = output + fmt.Sprintf("%s %s by @%s\n", id, title, author)
}

output = fmt.Sprintf("%s\nGenerated by [Derek](https://github.com/alexellis/derek/)\n", output)

log.Printf("Release notes: %q", output)

err = updateRelease(client, workingReleases.CurrentRelease, owner, repo, workingReleases.CurrentTag, output)

return err
}

func buildCommits(client *github.Client, workingReleases WorkingRelease, owner, repo, latestTag string) ([]github.RepositoryCommit, error) {
var err error
var commits []github.RepositoryCommit

opts := github.CommitsListOptions{
Since: workingReleases.PreviousDate,
Until: workingReleases.CurrentDate,
}

res, _, err := client.Repositories.ListCommits(context.Background(), owner, repo, &opts)

for _, c := range res {
commits = append(commits, *c)
}

if err != nil {
return nil, err
}

return commits, err
}

func buildClosedPRs(client *github.Client, workingReleases WorkingRelease, owner, repo, latestTag string) ([]github.PullRequest, error) {
opts := &github.PullRequestListOptions{
State: "closed",
Base: "master",
Expand All @@ -63,7 +130,7 @@ func updateReleaseNotes(client *github.Client, owner, repo, latestTag string) er

prs, _, err := client.PullRequests.List(context.Background(), owner, repo, opts)
if err != nil {
return err
return nil, err
}

log.Printf("Release [%s/%s:%s] start: %s\tend: %q\n",
Expand All @@ -80,22 +147,7 @@ func updateReleaseNotes(client *github.Client, owner, repo, latestTag string) er
return included[i].GetClosedAt().After(included[j].GetClosedAt())
})

output := fmt.Sprintf("Changelog for %s:\n", workingReleases.CurrentTag)

for _, pr := range included {
output = output + fmt.Sprintf("* PR #%d %s by @%s\n",
pr.GetNumber(),
pr.GetTitle(),
pr.GetUser().GetLogin())
}

output = fmt.Sprintf("%s\nGenerated by [Derek](https://github.com/alexellis/derek/)\n", output)

log.Printf("Release notes: %q", output)

err = updateRelease(client, workingReleases.CurrentRelease, owner, repo, workingReleases.CurrentTag, output)

return err
return included, nil
}

func getWorkingReleases(releases []*github.RepositoryRelease, owner, repo, tag string) WorkingRelease {
Expand Down

0 comments on commit 7d64f71

Please sign in to comment.