Now that we have a Lambda with the details of the GitHub issue loaded, we can render the content into a post for GitHub Pages.

Post Renderer

PostRenderer handles generation of the Markdown content for the GitHub Pages (Jekyll) blog post. Currently, it looks like this, though I’ll probably update the template as needed. Note I’m including GitHub issue tags both as keywords and Jekyll tags, which have slightly different formatting. Since GitHub labels can have spaces, I’m replacing those with hyphens.

public struct PostRenderer {

    static let formatter: DateFormatter = {
        let dateFormatter = DateFormatter()
        dateFormatter.locale = Locale(identifier: "en_US_POSIX")
        dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
        return dateFormatter

    public init() {}

    public func render(issue: GitHubIssue) -> String {
        let labels = { $ " ", with: "-") }
        let tags = labels.joined(separator: " ")
        let keywords = labels.joined(separator: ", ")
        let post = """
                  layout: post
                  title: \(issue.title)
                  permalink: /articles/:title
                  date: \(Self.formatter.string(from: issue.createdAt))
                  keywords: \(keywords)
                  tags: \(tags)
                  issue: \(issue.number)



                  <i><small>This article was written as an issue on my Blog repository on GitHub (see <a target="_blank" href="\(issue.number)">Issue #\(issue.number)</a>)</small></i>
        return post

Next Steps


Still need to find a way to push the new/updated file to the GitHub repo. Some options are:

  • Use git shell commands on Lambda (not trivial, and quite messy)
  • Start a container job to run the shell commands
  • Submit the file via GitHub REST API (as blob, and then commit)
  • Use PutFile on AWS CodeCommit API (pretty clean!) to commit the updates, then have GitHub sync from upstream/remote via Webhook.

Will keep working on it and figure out the best approach.

This article was written as an issue on my Blog repository on GitHub (see Issue #6)