Skip to content

Commit

Permalink
Merge pull request #296 from mergestat/audit-log-additional-cols
Browse files Browse the repository at this point in the history
feat: add `actor_location` column to the `github_org_audit_log` table
  • Loading branch information
patrickdevivo authored Jun 30, 2022
2 parents 58f2c6d + b08d715 commit ee2c342
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions extensions/internal/github/org_audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"context"
"encoding/json"
"io"
"strings"
"time"
Expand Down Expand Up @@ -33,6 +34,13 @@ type auditLogEntryContents struct {
}
ActorLogin string
ActorIp string
ActorLocation struct {
City string `json:"city"`
Country string `json:"country"`
CountryCode string `json:"countryCode"`
Region string `json:"region"`
RegionCode string `json:"regionCode"`
}
CreatedAt githubv4.DateTime
OperationType string
UserLogin string
Expand Down Expand Up @@ -107,6 +115,12 @@ func (i *iterOrgAuditLogs) Column(ctx vtab.Context, c int) error {
ctx.ResultText(current.Entry.ActorLogin)
case "actor_ip":
ctx.ResultText(current.Entry.ActorIp)
case "actor_location":
if s, err := json.Marshal(current.Entry.ActorLocation); err != nil {
return err
} else {
ctx.ResultText(string(s))
}
case "created_at":
t := current.Entry.CreatedAt
if t.IsZero() {
Expand Down Expand Up @@ -163,6 +177,7 @@ var orgAuditCols = []vtab.Column{
{Name: "actor_type", Type: "TEXT"},
{Name: "actor_login", Type: "TEXT"},
{Name: "actor_ip", Type: "TEXT"},
{Name: "actor_location", Type: "JSON"},
{Name: "created_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC},
{Name: "operation_type", Type: "TEXT"},
{Name: "user_login", Type: "TEXT"},
Expand Down
2 changes: 1 addition & 1 deletion extensions/internal/github/org_audit_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestOrgAuditLog(t *testing.T) {
t.Fatalf("failed to retrieve row contents: %v", err.Error())
}

if expected := 9; colCount != expected {
if expected := 10; colCount != expected {
t.Fatalf("expected %d columns, got: %d", expected, colCount)
}
}

0 comments on commit ee2c342

Please sign in to comment.