Skip to content

Commit 753adfd

Browse files
committed
create a new separate orgdata-code package, ready to be moved to a separate package
1 parent 928f693 commit 753adfd

File tree

9 files changed

+813
-445
lines changed

9 files changed

+813
-445
lines changed

pkg/orgdata-core/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Organizational Data Core Package
2+
3+
This package provides the core functionality for accessing and querying organizational data in a performant, indexed manner.
4+
5+
## Overview
6+
7+
The `orgdatacore` package is designed to be a reusable component that can be consumed by multiple services including:
8+
- Slack bots (ci-chat-bot)
9+
- REST APIs
10+
- CLI tools
11+
- Other organizational data consumers
12+
13+
## Features
14+
15+
- **Fast Data Access**: Pre-computed indexes enable O(1) lookups for common queries
16+
- **Thread-Safe**: Concurrent access with read-write mutex protection
17+
- **Hot Reload**: Support for dynamic data updates without service restart
18+
- **Flexible Data Sources**: Load from multiple JSON files with automatic merging
19+
- **Comprehensive Queries**: Employee, team, and organization lookups with membership validation
20+
21+
## Usage
22+
23+
### Basic Setup
24+
25+
```go
26+
package main
27+
28+
import (
29+
"github.com/openshift/ci-chat-bot/pkg/orgdata-core"
30+
)
31+
32+
func main() {
33+
// Create a new service
34+
service := orgdatacore.NewService()
35+
36+
// Load data from JSON files
37+
err := service.LoadFromFiles([]string{"comprehensive_index_dump.json"})
38+
if err != nil {
39+
log.Fatal(err)
40+
}
41+
}
42+
```
43+
44+
## Data Structure
45+
46+
The package expects data in the `comprehensive_index_dump.json` format generated by the Python `orglib` indexing system.
47+
48+
## Interface
49+
50+
The package implements the `ServiceInterface` which provides comprehensive organizational data access methods.
51+
52+
## Thread Safety
53+
54+
All public methods are thread-safe and can be called concurrently from multiple goroutines.
55+
56+
## Dependencies
57+
58+
- Go 1.19+
59+
- Standard library only (no external dependencies)

pkg/orgdata-core/example/main.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/openshift/ci-chat-bot/pkg/orgdata-core"
8+
)
9+
10+
func main() {
11+
// Create a new service
12+
service := orgdatacore.NewService()
13+
14+
fmt.Println("✅ Created new organizational data service")
15+
16+
// Load data from JSON files
17+
err := service.LoadFromFiles([]string{"../../test-data/comprehensive_index_dump.json"})
18+
if err != nil {
19+
log.Printf(" Could not load test data: %v", err)
20+
log.Println(" This is expected if test data is not available")
21+
log.Println(" The service is still functional for demonstration")
22+
} else {
23+
fmt.Println("✅ Loaded organizational data")
24+
25+
// Get version info
26+
version := service.GetVersion()
27+
fmt.Printf("📊 Data version: %d employees, %d orgs\n",
28+
version.EmployeeCount, version.OrgCount)
29+
30+
// Example queries (these will work if test data is loaded)
31+
if emp := service.GetEmployeeBySlackID("USE4Y4UG5"); emp != nil {
32+
fmt.Printf("👤 Found employee: %s (%s)\n", emp.FullName, emp.JobTitle)
33+
}
34+
35+
teams := service.GetTeamsForSlackID("USE4Y4UG5")
36+
if len(teams) > 0 {
37+
fmt.Printf("🏢 User is member of teams: %v\n", teams)
38+
}
39+
}
40+
41+
fmt.Println("\nCore package is ready for use!")
42+
fmt.Println(" - Import: github.com/openshift/ci-chat-bot/pkg/orgdata-core")
43+
fmt.Println(" - Interface: orgdatacore.ServiceInterface")
44+
fmt.Println(" - Implementation: orgdatacore.Service")
45+
}

pkg/orgdata-core/interface.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package orgdatacore
2+
3+
import "context"
4+
5+
// ServiceInterface defines the core interface for organizational data services
6+
type ServiceInterface interface {
7+
8+
// Core data access methods
9+
10+
GetEmployeeByUID(uid string) *Employee
11+
GetEmployeeBySlackID(slackID string) *Employee
12+
GetTeamByName(teamName string) *Team
13+
GetOrgByName(orgName string) *Org
14+
15+
// Membership queries
16+
17+
GetTeamsForUID(uid string) []string
18+
GetTeamsForSlackID(slackID string) []string
19+
GetTeamMembers(teamName string) []Employee
20+
IsEmployeeInTeam(uid string, teamName string) bool
21+
IsSlackUserInTeam(slackID string, teamName string) bool
22+
23+
// Organization queries
24+
25+
IsEmployeeInOrg(uid string, orgName string) bool
26+
IsSlackUserInOrg(slackID string, orgName string) bool
27+
GetUserOrganizations(slackUserID string) []OrgInfo
28+
29+
// Data management
30+
31+
GetVersion() DataVersion
32+
LoadFromFiles(filePaths []string) error
33+
StartConfigMapWatcher(ctx context.Context, configMapPaths []string)
34+
}
35+
36+
// OrgInfo represents organization information for a user
37+
type OrgInfo struct {
38+
Name string `json:"name"`
39+
Type string `json:"type"`
40+
}

0 commit comments

Comments
 (0)