Add issue closer
This commit is contained in:
@@ -136,9 +136,10 @@ const (
|
||||
ActionSearch = "search"
|
||||
ActionGithubIssueLabeler = "github-issue-labeler"
|
||||
ActionGithubIssueOpener = "github-issue-opener"
|
||||
ActionGithubIssueCloser = "github-issue-closer"
|
||||
)
|
||||
|
||||
var AvailableActions = []string{ActionSearch, ActionGithubIssueLabeler, ActionGithubIssueOpener}
|
||||
var AvailableActions = []string{ActionSearch, ActionGithubIssueLabeler, ActionGithubIssueOpener, ActionGithubIssueCloser}
|
||||
|
||||
func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
||||
actions := []Action{}
|
||||
@@ -148,7 +149,7 @@ func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
||||
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(action.Config), &config); err != nil {
|
||||
fmt.Println("Error unmarshalling connector config", err)
|
||||
fmt.Println("Error unmarshalling action config", err)
|
||||
continue
|
||||
}
|
||||
fmt.Println("Config", config)
|
||||
@@ -160,6 +161,8 @@ func (a *AgentConfig) availableActions(ctx context.Context) []Action {
|
||||
actions = append(actions, external.NewGithubIssueLabeler(ctx, config))
|
||||
case ActionGithubIssueOpener:
|
||||
actions = append(actions, external.NewGithubIssueOpener(ctx, config))
|
||||
case ActionGithubIssueCloser:
|
||||
actions = append(actions, external.NewGithubIssueCloser(ctx, config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +209,7 @@ func (a *AgentConfig) availableConnectors() []Connector {
|
||||
case ConnectorDiscord:
|
||||
connectors = append(connectors, connector.NewDiscord(config))
|
||||
case ConnectorGithubIssues:
|
||||
connectors = append(connectors, connector.NewGithub(config))
|
||||
connectors = append(connectors, connector.NewGithubIssueWatcher(config))
|
||||
}
|
||||
}
|
||||
return connectors
|
||||
@@ -407,7 +410,7 @@ func (a *AgentPool) Remove(name string) error {
|
||||
}
|
||||
|
||||
func (a *AgentPool) Save() error {
|
||||
data, err := json.Marshal(a.pool)
|
||||
data, err := json.MarshalIndent(a.pool, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type GithubIssues struct {
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
func NewGithub(config map[string]string) *GithubIssues {
|
||||
func NewGithubIssueWatcher(config map[string]string) *GithubIssues {
|
||||
client := github.NewClient(nil).WithAuthToken(config["token"])
|
||||
interval, err := time.ParseDuration(config["pollInterval"])
|
||||
if err != nil {
|
||||
@@ -57,7 +57,7 @@ func (g *GithubIssues) Start(a *agent.Agent) {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
fmt.Println("Fire in da hole!")
|
||||
fmt.Println("Looking into github issues...")
|
||||
g.issuesService()
|
||||
case <-a.Context().Done():
|
||||
return
|
||||
@@ -86,12 +86,27 @@ func (g *GithubIssues) issuesService() {
|
||||
if issue.IsPullRequest() {
|
||||
continue
|
||||
}
|
||||
userName := *issue.User.Name
|
||||
labels := []string{}
|
||||
for _, l := range issue.Labels {
|
||||
labels = append(labels, l.GetName())
|
||||
}
|
||||
|
||||
// Get user that opened the issue
|
||||
userNameLogin := issue.GetUser().Login
|
||||
userName := ""
|
||||
if userNameLogin != nil {
|
||||
userName = *userNameLogin
|
||||
}
|
||||
|
||||
if userName == user.GetLogin() {
|
||||
fmt.Println("Ignoring issue opened by the bot")
|
||||
continue
|
||||
}
|
||||
messages := []openai.ChatCompletionMessage{
|
||||
{
|
||||
Role: "system",
|
||||
Content: fmt.Sprintf(
|
||||
`This is a conversation with an user ("%s") that opened a Github issue with title "%s" in the repository "%s" owned by "%s" .`, userName, issue.GetTitle(), g.repository, g.owner),
|
||||
`This is a conversation with an user ("%s") that opened a Github issue with title "%s" in the repository "%s" owned by "%s". The issue is the issue number %d. Current labels: %+v`, userName, issue.GetTitle(), g.repository, g.owner, issue.GetNumber(), labels),
|
||||
},
|
||||
{
|
||||
Role: "user",
|
||||
|
||||
Reference in New Issue
Block a user