usermapping

package
v0.0.0-...-72f1ef6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package usermapping provides GitHub-to-Slack user mapping functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitHubEmailLookup

type GitHubEmailLookup interface {
	Lookup(ctx context.Context, username, organization string) (*ghmailto.Result, error)
	Guess(ctx context.Context, username, organization string, opts ghmailto.GuessOptions) (*ghmailto.GuessResult, error)
}

GitHubEmailLookup defines the interface for GitHub email lookup operations.

type ReverseMapping

type ReverseMapping struct {
	CachedAt       time.Time
	SlackUserID    string
	SlackUsername  string
	SlackEmail     string
	GitHubUsername string
	MatchMethod    string // "email_lookup", "guess", "config_override"
	Confidence     int    // Match confidence (0-100)
}

ReverseMapping represents a Slack-to-GitHub user mapping.

type ReverseService

type ReverseService struct {
	// contains filtered or unexported fields
}

ReverseService handles Slack-to-GitHub user mapping (reverse of the main Service).

func NewReverseService

func NewReverseService(_ *slack.Client, githubToken string) *ReverseService

NewReverseService creates a new reverse mapping service (Slack → GitHub).

func (*ReverseService) CacheStats

func (s *ReverseService) CacheStats() (total int, expired int)

CacheStats returns cache statistics for reverse mappings.

func (*ReverseService) ClearCache

func (s *ReverseService) ClearCache()

ClearCache clears the reverse mapping cache.

func (*ReverseService) LookupGitHub

func (s *ReverseService) LookupGitHub(ctx context.Context, slackClient SlackAPI, slackUserID, organization, domain string) (*ReverseMapping, error)

LookupGitHub attempts to find a GitHub username for a Slack user ID. It uses email matching via gh-mailto to find the best GitHub username match.

func (*ReverseService) SetOverrides

func (s *ReverseService) SetOverrides(overrides map[string]string)

SetOverrides updates the manual user mapping overrides from config. Format: githubUsername -> email.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles GitHub-to-Slack user mapping.

func New

func New(slackClient *slack.Client, githubToken string) *Service

New creates a new user mapping service.

func NewForTesting

func NewForTesting(slackClient SlackAPI, githubLookup GitHubEmailLookup) *Service

NewForTesting creates a new Service with injectable dependencies for testing.

func (*Service) CacheStats

func (s *Service) CacheStats() (total int, expired int)

CacheStats returns cache statistics.

func (*Service) ClearCache

func (s *Service) ClearCache()

ClearCache clears the user mapping cache.

func (*Service) FormatUserMention

func (s *Service) FormatUserMention(ctx context.Context, githubUsername, organization, domain string) string

FormatUserMention formats a GitHub username as a Slack mention if mapping exists. Falls back to @githubUsername if no Slack mapping is found.

func (*Service) FormatUserMentions

func (s *Service) FormatUserMentions(ctx context.Context, githubUsernames []string, organization, domain string) string

FormatUserMentions formats multiple GitHub usernames as Slack mentions. Returns formatted string like "@slackUser1, @slackUser2" or falls back to GitHub usernames.

func (*Service) SetGitHubLookup

func (s *Service) SetGitHubLookup(lookup GitHubEmailLookup)

SetGitHubLookup sets the GitHub email lookup service for testing. This is only exported for integration tests.

func (*Service) SetSlackClient

func (s *Service) SetSlackClient(client SlackAPI)

SetSlackClient sets the Slack client for testing. This is only exported for integration tests.

func (*Service) SlackHandle

func (s *Service) SlackHandle(ctx context.Context, githubUsername, organization, domain string) (string, error)

SlackHandle attempts to find a Slack user ID for a GitHub username. It uses email matching to find the best Slack user match and returns the Slack user ID (e.g., "U1234567890").

func (*Service) SlackHandles

func (s *Service) SlackHandles(ctx context.Context, githubUsernames []string, organization, domain string) (map[string]string, error)

SlackHandles performs batch lookup of multiple GitHub users to Slack user IDs. Returns a map of GitHub username to Slack user ID (empty string if not found).

type SlackAPI

type SlackAPI interface {
	GetUserByEmailContext(ctx context.Context, email string) (*slack.User, error)
	GetUserInfo(userID string) (*slack.User, error)
}

SlackAPI defines the interface for Slack API operations needed by the mapping service.

type UserMapping

type UserMapping struct {
	CachedAt       time.Time
	GitHubUsername string
	SlackUserID    string
	SlackUsername  string
	MatchedEmail   string
	Confidence     int // Match confidence (0-100)
}

UserMapping represents a GitHub-to-Slack user mapping.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL