Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
- name: Install dependencies
run: go mod tidy

- name: Check formatting
run: test -z "$(gofmt -l .)"

- name: Vet
run: go vet ./...

- name: Run Tests
run: go test -v ./...

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
coverage.*
*.coverprofile
profile.cov
*.log

# Dependency directories (remove the comment below to include it)
# vendor/
Expand All @@ -33,4 +34,4 @@ go.work.sum
sentinent-backend

# db
sentinent.db
sentinent.db
4 changes: 2 additions & 2 deletions handlers/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ func JiraIssueActionHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Failed to perform transition: "+err.Error(), http.StatusBadRequest)
return
}

// Optional: Trigger a background sync to reflect changes quickly
go services.SyncJiraSignals(userID, workspaceID)

w.WriteHeader(http.StatusNoContent)
return
}
Expand Down
8 changes: 4 additions & 4 deletions models/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type ExternalIntegration struct {
}

type IntegrationStatus struct {
Provider string `json:"provider"`
Configured bool `json:"configured"`
Connected bool `json:"connected"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
Provider string `json:"provider"`
Configured bool `json:"configured"`
Connected bool `json:"connected"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
42 changes: 21 additions & 21 deletions models/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package models
import "time"

const (
SourceTypeSlack = "slack"
SourceTypeGitHub = "github"
SourceTypeJira = "jira"
SignalStatusUnread = "unread"
SignalStatusRead = "read"
SourceTypeSlack = "slack"
SourceTypeGitHub = "github"
SourceTypeJira = "jira"
SignalStatusUnread = "unread"
SignalStatusRead = "read"
SignalStatusArchived = "archived"
)

type Signal struct {
ID int `json:"id"`
UserID int `json:"user_id"`
WorkspaceID int `json:"workspace_id,omitempty"`
SourceType string `json:"source_type"`
SourceID string `json:"source_id"`
ExternalID string `json:"external_id,omitempty"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Author string `json:"author,omitempty"`
Body string `json:"body,omitempty"`
URL string `json:"url,omitempty"`
Status string `json:"status"`
SourceMetadata interface{} `json:"source_metadata,omitempty"`
ReceivedAt time.Time `json:"received_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID int `json:"id"`
UserID int `json:"user_id"`
WorkspaceID int `json:"workspace_id,omitempty"`
SourceType string `json:"source_type"`
SourceID string `json:"source_id"`
ExternalID string `json:"external_id,omitempty"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Author string `json:"author,omitempty"`
Body string `json:"body,omitempty"`
URL string `json:"url,omitempty"`
Status string `json:"status"`
SourceMetadata interface{} `json:"source_metadata,omitempty"`
ReceivedAt time.Time `json:"received_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type GitHubMetadata struct {
Expand Down
4 changes: 0 additions & 4 deletions server.log

This file was deleted.

3 changes: 1 addition & 2 deletions services/github_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"testing"
"time"

"golang.org/x/oauth2"
_ "github.com/mattn/go-sqlite3"
"golang.org/x/oauth2"
)

func setupGitHubCoverageTestDB(t *testing.T) func() {
Expand Down Expand Up @@ -273,4 +273,3 @@ func TestFetchAssignedIssuesAndListAccessibleReposWithLocalGitHubServer(t *testi
t.Fatalf("unexpected repo payload: %+v", repos[0])
}
}

22 changes: 11 additions & 11 deletions services/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type JiraIssue struct {
ID string `json:"id"`
Key string `json:"key"`
Fields struct {
Summary string `json:"summary"`
Summary string `json:"summary"`
Description interface{} `json:"description"`
Status struct {
Name string `json:"name"`
Expand Down Expand Up @@ -358,7 +358,7 @@ func parseADFToText(node interface{}) string {
}

nodeType, _ := m["type"].(string)

var sb strings.Builder

if nodeType == "text" {
Expand Down Expand Up @@ -391,9 +391,9 @@ func formatDescription(desc interface{}) string {
if desc == nil {
return ""
}

text := strings.TrimSpace(parseADFToText(desc))

if len(text) > 500 {
return text[:500] + "..."
}
Expand Down Expand Up @@ -435,7 +435,7 @@ type JiraTransition struct {
// GetAvailableTransitions fetches transitions for a specific issue
func GetAvailableTransitions(client *http.Client, cloudId string, issueKey string) ([]JiraTransition, error) {
apiURL := fmt.Sprintf("https://api.atlassian.com/ex/jira/%s/rest/api/3/issue/%s/transitions", cloudId, issueKey)

req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -466,7 +466,7 @@ func GetAvailableTransitions(client *http.Client, cloudId string, issueKey strin
// PerformTransition executes a status change on a specific issue
func PerformTransition(client *http.Client, cloudId string, issueKey string, transitionID string) error {
apiURL := fmt.Sprintf("https://api.atlassian.com/ex/jira/%s/rest/api/3/issue/%s/transitions", cloudId, issueKey)

requestBody, _ := json.Marshal(map[string]interface{}{
"transition": map[string]string{
"id": transitionID,
Expand Down Expand Up @@ -498,12 +498,12 @@ func PerformTransition(client *http.Client, cloudId string, issueKey string, tra
// AddJiraComment adds a comment to a specific issue
func AddJiraComment(client *http.Client, cloudId string, issueKey string, commentText string) error {
apiURL := fmt.Sprintf("https://api.atlassian.com/ex/jira/%s/rest/api/3/issue/%s/comment", cloudId, issueKey)

// Jira API v3 expects ADF for comments.
requestBody, _ := json.Marshal(map[string]interface{}{
"body": map[string]interface{}{
"version": 1,
"type": "doc",
"type": "doc",
"content": []map[string]interface{}{
{
"type": "paragraph",
Expand Down Expand Up @@ -582,7 +582,7 @@ func saveJiraIssueAsSignal(userID, workspaceID int, issue JiraIssue, cloudURL st
if issue.Fields.Priority != nil {
priorityName = issue.Fields.Priority.Name
}

assigneeName := ""
if issue.Fields.Assignee != nil {
assigneeName = issue.Fields.Assignee.DisplayName
Expand All @@ -609,10 +609,10 @@ func saveJiraIssueAsSignal(userID, workspaceID int, issue JiraIssue, cloudURL st
updatedAt := parseJiraDate(issue.Fields.Updated)

// Since SourceMetadata in models.Signal is strongly typed to GitHubMetadata for now,
// we will likely store Jira metadata in a new field or JSON encode it into the body to be generic.
// we will likely store Jira metadata in a new field or JSON encode it into the body to be generic.
// Wait, the model update we applied added JiraMetadata but didn't modify Signal struct's SourceMetadata type!
// We might need to change it to interface{} or add JiraMetadata *JiraMetadata

// But let's just save it.
_, err := database.DB.Exec(
`INSERT INTO signals
Expand Down
Loading