Skip to content

Commit

Permalink
Adds support for skipping "private" todos
Browse files Browse the repository at this point in the history
  • Loading branch information
bakatz committed Jul 19, 2023
1 parent f57bd15 commit 4d50663
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/aws/aws-lambda-go/lambda"
Expand All @@ -24,6 +25,7 @@ type Response struct {
}

const (
PRIVATE_ENTITY_IDENTIFIER = "!private"
LOOKBACK_WINDOW_MINUTES = 60
SUCCESS_MESSAGE = "Function finished without errors"
CONNECTION_TIMEOUT_DURATION = 5 * time.Second
Expand All @@ -33,6 +35,7 @@ const (
projects {
id
name
pitch
website_url
todos(completed:true, orderBy: { completedAt:desc }) {
id
Expand Down Expand Up @@ -114,9 +117,15 @@ func Handler(ctx context.Context) (Response, error) {
startOfLookbackWindow := time.Now().UTC().Add(-LOOKBACK_WINDOW_MINUTES * time.Minute)
numTodosTweeted := 0
for _, project := range wipResponse.Data.Viewer.Projects {
// Skip replicating all todos in projects marked as "private"
if strings.Contains(project.Pitch, PRIVATE_ENTITY_IDENTIFIER) {
continue
}

for _, todo := range project.Todos {
// If this todo was completed more than an hour ago, don't bother tweeting about it because we've already covered it in a previous run (we run every hour to catch todos from the previous hour)
if todo.CompletedAt.Before(startOfLookbackWindow) {
// Also skip private todos that should not be replicated to twitter.
if todo.CompletedAt.Before(startOfLookbackWindow) || strings.Contains(todo.Body, PRIVATE_ENTITY_IDENTIFIER) {
continue
}
tweetMessage := "✅ " + todo.Body
Expand Down
1 change: 1 addition & 0 deletions lib/wip/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Todo struct {
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Pitch string `json:"pitch"`
WebsiteURL string `json:"website_url"`
Todos []Todo `json:"todos"`
}
Expand Down

0 comments on commit 4d50663

Please sign in to comment.