blob: 03be2b99cd6a012a2ea638cb4089819f337c74b1 [file] [log] [blame]
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package githubdocs implements converting GitHub issues into text docs
// for [golang.org/x/oscar/internal/docs].
package githubdocs
import (
"context"
"fmt"
"log/slog"
"golang.org/x/oscar/internal/docs"
"golang.org/x/oscar/internal/github"
"golang.org/x/oscar/internal/storage/timed"
)
// Sync writes to dc docs corresponding to each issue in gh that is
// new since the last call to Sync.
//
// If an issue is edited on GitHub, it will appear new in gh and
// the new text will be written to dc, replacing the old issue text.
// Only the issue body (what looks like the top comment in the UI)
// is saved as a document.
// The document ID for each issue is its GitHub URL: "https://github.com/<org>/<repo>/issues/<n>".
func Sync(ctx context.Context, lg *slog.Logger, dc *docs.Corpus, gh *github.Client) error {
w := gh.EventWatcher("githubdocs")
for e := range w.Recent() {
if e.API != "/issues" {
continue
}
lg.Debug("githubdocs sync", "issue", e.Issue, "dbtime", e.DBTime)
issue := e.Typed.(*github.Issue)
title := cleanTitle(issue.Title)
text := cleanBody(issue.Body)
dc.Add(fmt.Sprintf("https://github.com/%s/issues/%d", e.Project, e.Issue), title, text)
w.MarkOld(e.DBTime)
}
return nil
}
// Restart causes the next call to Sync to behave as if
// it has never sync'ed any issues before.
// The result is that all issues will be reconverted to doc form
// and re-added.
// Docs that have not changed since the last addition to the corpus
// will appear unmodified; others will be marked new in the corpus.
func Restart(lg *slog.Logger, gh *github.Client) {
gh.EventWatcher("githubdocs").Restart()
}
// Latest returns the latest known DBTime marked old by the client's Watcher.
func Latest(gh *github.Client) timed.DBTime {
return gh.EventWatcher("githubdocs").Latest()
}
// cleanTitle should clean the title for indexing.
// For now we assume the LLM is good enough at Markdown not to bother.
func cleanTitle(title string) string {
// TODO
return title
}
// cleanBody should clean the body for indexing.
// For now we assume the LLM is good enough at Markdown not to bother.
// In the future we may want to make various changes like inlining
// the programs associated with playground URLs,
// and we may also want to remove any HTML tags from the Markdown.
func cleanBody(body string) string {
// TODO
return body
}