Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertMarkdownToUTF8(r io.Reader) (io.Reader, error)
- func ConvertZipToPackfile(ctx context.Context, problemFiles common.ProblemFiles, ...) (*git.Oid, error)
- func CreatePackfile(ctx context.Context, contents map[string]io.Reader, ...) (*git.Oid, error)
- func HealthHandler(rootPath string, port uint16) http.Handler
- func InitRepository(ctx context.Context, repositoryPath string) (*git.Repository, error)
- func NewGitHandler(opts GitHandlerOpts) http.Handler
- func NewGitProtocol(opts GitProtocolOpts) *githttp.GitProtocol
- func NewZipHandler(opts ZipHandlerOpts) http.Handler
- func NormalizeCase(r io.Reader) (io.Reader, error)
- func SetupMetrics(programVersion string) (base.Metrics, http.Handler)
- type Comment
- type FakeInteractiveSettingsCompiler
- type GitHandlerOpts
- type GitProtocolOpts
- type InteractiveSettingsCompiler
- type LedgerIteration
- type LibinteractiveCompiler
- type LineEndingNormalizer
- type MetaConfig
- type PublishingConfig
- type Range
- type UpdateResult
- type UpdatedFile
- type ZipHandlerOpts
- type ZipMergeStrategy
Constants ¶
const ( // GitAttributesContents is what the .gitattributes and info/attributes files // contain. GitAttributesContents = "cases/* -diff -delta -merge -text -crlf\n" )
Variables ¶
var ( // ErrNotAReview is returned if a merge to master is attempted and does not // come from a review commit. ErrNotAReview = stderrors.New("not-a-review") // ErrJSONParseError is returned if one of the JSON files fails to be parsed. ErrJSONParseError = stderrors.New("json-parse-error") // ErrChangeMissingSettingsJSON is returned if the settings.json file is missing. ErrChangeMissingSettingsJSON = stderrors.New("change-missing-settings-json") // ErrPublishedNotFromMaster is returned if an update to the published branch // is attempted and the new reference does not point to a commit in the // master branch. ErrPublishedNotFromMaster = stderrors.New("published-must-point-to-commit-in-master") // ErrConfigSubdirectoryMissingTarget is returned if a 'subdirectory' // publishing config is missing a 'target' entry. ErrConfigSubdirectoryMissingTarget = stderrors.New("config-subdirectory-missing-target") // ErrConfigInvalidPublishingMode is returned if a publishing config is not // 'subdirectory' or 'mirror'. ErrConfigInvalidPublishingMode = stderrors.New("config-invalid-publishing-mode") // ErrConfigRepositoryNotAbsoluteURL is returned if a publishing config does // not have a valid, absolute URL for 'repository'. ErrConfigRepositoryNotAbsoluteURL = stderrors.New("config-repository-not-absolute-url") // ErrConfigBadLayout is returned if the refs/meta/config structure does not // contain the correct layout. ErrConfigBadLayout = stderrors.New("config-bad-layout") // ErrTestsBadLayout is returned if the tests/ directory does not contain the // correct layout. ErrTestsBadLayout = stderrors.New("tests-bad-layout") // ErrInteractiveBadLayout is returned if the interactive/ directory does not // contain the correct layout. ErrInteractiveBadLayout = stderrors.New("interactive-bad-layout") // ErrProblemBadLayout is returned if the problem structure does not contain the // correct layout. ErrProblemBadLayout = stderrors.New("problem-bad-layout") // ErrReviewBadLayout is returned if the review structure does not contain // the correct layout. ErrReviewBadLayout = stderrors.New("review-bad-layout") // ErrMismatchedInputFile is returned if there is an .in without an .out. ErrMismatchedInputFile = stderrors.New("mismatched-input-file") // ErrInternalGit is returned if there is a problem with the git structure. ErrInternalGit = stderrors.New("internal-git-error") // ErrInternal is returned if there is an internal error. ErrInternal = stderrors.New("internal-error") // ErrTooManyObjects is returned if the packfile has too many objects. ErrTooManyObjects = stderrors.New("too-many-objects-in-packfile") // ErrInvalidZipFilename is returned if a path in the .zip is invalid. ErrInvalidZipFilename = stderrors.New("invalid-zip-filename") // ErrNoStatements is returned if the problem does not have any statements. ErrNoStatements = stderrors.New("no-statements") // ErrNoEsStatement is returned if the problem does not have the default // Spanish statement. ErrNoEsStatement = stderrors.New("no-es-statement") // ErrSlowRejected is returned if the maximum runtime would exceed the hard // limit. ErrSlowRejected = stderrors.New("slow-rejected") // ErrInvalidTestplan is returned if the testplan file is not valid. ErrInvalidTestplan = stderrors.New("invalid-testplan") // ErrInvalidMarkup is returned if the markup file is not valid. ErrInvalidMarkup = stderrors.New("invalid-markup") // DefaultCommitDescriptions describes which files go to which branches. DefaultCommitDescriptions = []githttp.SplitCommitDescription{ { ReferenceName: "refs/heads/public", PathRegexps: []*regexp.Regexp{ regexp.MustCompile("^.gitattributes$"), regexp.MustCompile("^.gitignore$"), regexp.MustCompile(`^statements(/[^/]+\.(md|markdown|gif|jpe?g|png|svg|py[23]?|cpp\w*|c|java|kp|kj|in|out))?$`), regexp.MustCompile("^examples(/[^/]+\\.(in|out))?$"), regexp.MustCompile("^interactive/Main\\.distrib\\.[a-z0-9]+$"), regexp.MustCompile("^interactive/examples(/[^/]+\\.(in|out))?$"), regexp.MustCompile("^validator\\.distrib\\.[a-z]+$"), regexp.MustCompile("^settings\\.distrib\\.json$"), }, }, { ReferenceName: "refs/heads/protected", PathRegexps: []*regexp.Regexp{ regexp.MustCompile(`^solutions(/[^/]+\.(md|markdown|gif|jpe?g|png|svg|py[23]?|cpp\w*|c|java|kp|kj|in|out))?$`), regexp.MustCompile("^tests(/.*)?$"), }, }, { ReferenceName: "refs/heads/private", PathRegexps: []*regexp.Regexp{ regexp.MustCompile("^cases(/[^/]+\\.(in|out))?$"), regexp.MustCompile("^interactive/Main\\.[a-z0-9]+$"), regexp.MustCompile("^interactive/[^/]+\\.idl$"), regexp.MustCompile("^validator\\.[a-z0-9]+$"), regexp.MustCompile("^settings\\.json$"), }, }, } )
var ( // UTF8BOM is the UTF-8 Byte order mark. UTF8BOM = []byte{0xEF, 0xBB, 0xBF} // UTF16LEBOM is the UTF-16 (LE) Byte order mark. UTF16LEBOM = []byte{0xFF, 0xFE} // UTF16BEBOM is the UTF-16 (BE) Byte order mark. UTF16BEBOM = []byte{0xFE, 0xFF} // UTF32LEBOM is the UTF-16 (LE) Byte order mark. UTF32LEBOM = []byte{0xFF, 0xFE, 0x00, 0x00} // UTF32BEBOM is the UTF-16 (BE) Byte order mark. UTF32BEBOM = []byte{0x00, 0x00, 0xFE, 0xFF} )
Functions ¶
func ConvertMarkdownToUTF8 ¶
ConvertMarkdownToUTF8 performs a best-effort detection of the encoding of the supplied reader and returns a Reader that is UTF-8 encoded.
func ConvertZipToPackfile ¶
func ConvertZipToPackfile( ctx context.Context, problemFiles common.ProblemFiles, settings *common.ProblemSettings, zipMergeStrategy ZipMergeStrategy, repo *git.Repository, parent *git.Oid, author, committer *git.Signature, commitMessage string, acceptsSubmissions bool, w io.Writer, log logging.Logger, ) (*git.Oid, error)
ConvertZipToPackfile receives a .zip file from the caller and converts it into a git packfile that can be used to update the repository.
func CreatePackfile ¶
func CreatePackfile( ctx context.Context, contents map[string]io.Reader, settings *common.ProblemSettings, zipMergeStrategy ZipMergeStrategy, repo *git.Repository, parent *git.Oid, author, committer *git.Signature, commitMessage string, w io.Writer, log logging.Logger, ) (*git.Oid, error)
CreatePackfile creates a packfile that contains a commit that contains the specified contents plus a subset of the parent commit's tree, depending of the value of zipMergeStrategy.
func HealthHandler ¶ added in v1.8.8
HealthHandler is an implementation of k8s readiness and liveness checks. The liveness check just returns HTTP 200 (because the server is reachable), but the readiness check tries to interact with the service by requesting the settings.json file of the sumas problem. Getting a 404 is fine.
func InitRepository ¶
InitRepository is a wrapper around git.CreateRepository() that also adds omegaUp-specific files to the repository.
func NewGitHandler ¶ added in v1.8.9
func NewGitHandler(opts GitHandlerOpts) http.Handler
NewGitHandler is the HTTP handler for the omegaUp git server.
func NewGitProtocol ¶
func NewGitProtocol(opts GitProtocolOpts) *githttp.GitProtocol
NewGitProtocol creates a new GitProtocol with the provided authorization callback.
func NewZipHandler ¶ added in v1.8.9
func NewZipHandler(opts ZipHandlerOpts) http.Handler
NewZipHandler is the HTTP handler that allows uploading .zip files.
func NormalizeCase ¶
NormalizeCase performs a best-effort conversion to UTF-8 and normalizes the end-of-line characters.
Types ¶
type Comment ¶
type Comment struct { Author string `json:"author"` Date int64 `json:"date"` Done bool `json:"done"` Filename string `json:"filename"` IterationUUID string `json:"iterationUuid"` Message string `json:"message"` ParentUUID *string `json:"parentUuid"` Range *Range `json:"range"` ReplacementSuggestion bool `json:"replacementSuggestion"` UUID string `json:"uuid"` }
Comment is a comment in the code review.
type FakeInteractiveSettingsCompiler ¶
type FakeInteractiveSettingsCompiler struct { Settings *common.InteractiveSettings Err error }
FakeInteractiveSettingsCompiler is an implementation of InteractiveSettingsCompiler that just returns pre-specified settings.
func (*FakeInteractiveSettingsCompiler) GetInteractiveSettings ¶
func (c *FakeInteractiveSettingsCompiler) GetInteractiveSettings( contents io.Reader, moduleName string, parentLang string, ) (*common.InteractiveSettings, error)
GetInteractiveSettings returns the pre-specified settings.
type GitHandlerOpts ¶ added in v1.8.9
type GitHandlerOpts struct { RootPath string Protocol *githttp.GitProtocol Metrics base.Metrics Log logging.Logger LockfileManager *githttp.LockfileManager Tracing tracing.Provider }
GitHandlerOpts contains all the possible options to initialize the git Server.
type GitProtocolOpts ¶ added in v1.8.9
type GitProtocolOpts struct { githttp.GitProtocolOpts AllowDirectPushToMaster bool HardOverallWallTimeLimit base.Duration InteractiveSettingsCompiler InteractiveSettingsCompiler LockfileManager *githttp.LockfileManager }
GitProtocolOpts contains all the possible options to initialize the git protocol.
type InteractiveSettingsCompiler ¶
type InteractiveSettingsCompiler interface { // GetInteractiveSettings converts the .idl file contents and the module name // + parent language pair into a common.InteractiveSettings object. GetInteractiveSettings( idlFileContents io.Reader, moduleName string, parentLang string, ) (*common.InteractiveSettings, error) }
InteractiveSettingsCompiler converts the .idl file contents and the module name + parent language pair into a common.InteractiveSettings object.
type LedgerIteration ¶
type LedgerIteration struct { Author string `json:"author"` Date int64 `json:"date"` Summary string `json:"summary"` UUID string `json:"uuid"` Vote string `json:"vote"` }
LedgerIteration is an entry in the iteration ledger.
type LibinteractiveCompiler ¶
type LibinteractiveCompiler struct { // A way to optionally override the path of libinteractive.jar. LibinteractiveJarPath string Log logging.Logger }
LibinteractiveCompiler is an implementation of InteractiveSettingsCompiler that uses the real libinteractive.jar to convert the .idl file.
func (*LibinteractiveCompiler) GetInteractiveSettings ¶
func (c *LibinteractiveCompiler) GetInteractiveSettings( contents io.Reader, moduleName string, parentLang string, ) (*common.InteractiveSettings, error)
GetInteractiveSettings calls libinteractive.jar to produce the common.InteractiveSettings.
type LineEndingNormalizer ¶
type LineEndingNormalizer struct {
// contains filtered or unexported fields
}
LineEndingNormalizer is an io.Reader that trims trailing whitespace and converts line endings to \n.
func NewLineEndingNormalizer ¶
func NewLineEndingNormalizer(rd io.Reader) *LineEndingNormalizer
NewLineEndingNormalizer returns a LineEndingNormalizer from the provided io.Reader.
type MetaConfig ¶ added in v1.3.17
type MetaConfig struct {
Publishing PublishingConfig `json:"publishing"`
}
MetaConfig represents the contents of config.json in refs/meta/config.
type PublishingConfig ¶
type PublishingConfig struct { Mode string `json:"mode"` Repository string `json:"repository"` Target string `json:"target,omitempty"` Branch string `json:"branch,omitempty"` }
PublishingConfig represents the publishing section of config.json in refs/meta/config.
type Range ¶
type Range struct { LineStart int `json:"lineStart"` LineEnd int `json:"lineEnd"` ColStart int `json:"colStart"` ColEnd int `json:"colEnd"` }
Range is a range in the source code that is associated with a Comment.
type UpdateResult ¶ added in v1.3.0
type UpdateResult struct { Status string `json:"status"` Error string `json:"error,omitempty"` UpdatedRefs []githttp.UpdatedRef `json:"updated_refs,omitempty"` UpdatedFiles []UpdatedFile `json:"updated_files"` }
UpdateResult represents the result of running this command.
func PushZip ¶ added in v1.3.0
func PushZip( ctx context.Context, problemFiles common.ProblemFiles, authorizationLevel githttp.AuthorizationLevel, repo *git.Repository, lockfile *githttp.Lockfile, authorUsername string, commitMessage string, problemSettings *common.ProblemSettings, zipMergeStrategy ZipMergeStrategy, acceptsSubmissions bool, updatePublished bool, protocol *githttp.GitProtocol, log logging.Logger, ) (*UpdateResult, error)
PushZip reads the contents of the .zip file pointed at to by problemFiles, creates a packfile out of it, and pushes it to the master branch of the repository.
type UpdatedFile ¶ added in v1.3.0
UpdatedFile represents an updated file. Type is either "added", "deleted", or "modified".
func GetUpdatedFiles ¶ added in v1.3.0
func GetUpdatedFiles( ctx context.Context, repo *git.Repository, updatedRefs []githttp.UpdatedRef, ) ([]UpdatedFile, error)
GetUpdatedFiles returns the files that were updated in the master branch.
type ZipHandlerOpts ¶ added in v1.8.9
type ZipHandlerOpts struct { RootPath string Protocol *githttp.GitProtocol Metrics base.Metrics Log logging.Logger LockfileManager *githttp.LockfileManager Tracing tracing.Provider }
ZipHandlerOpts contains all the possible options to initialize the zip handler.
type ZipMergeStrategy ¶ added in v1.3.0
type ZipMergeStrategy int
A ZipMergeStrategy represents the strategy to use when merging the trees of a .zip upload and its parent.
const ( // ZipMergeStrategyOurs will use the parent commit's tree as-is without even // looking at the contents of the .zip or doing any kind of merge. This is // exactly what what git-merge does with '-s ours'. ZipMergeStrategyOurs ZipMergeStrategy = iota // ZipMergeStrategyTheirs will use the tree that was contained in the .zip // as-is without even looking at the parent tree or doing any kind of merge. // This the opposite of ZipMergeStrategyOurs, and has no equivalent in // git-merge. ZipMergeStrategyTheirs // ZipMergeStrategyStatementsOurs will keep the statements/ subtree from the // parent commit as-is, and replace the rest of the tree with the contents of // the .zip file. ZipMergeStrategyStatementsOurs // ZipMergeStrategyRecursiveTheirs will merge the contents of the .zip file // with the parent commit's tree, preferring whatever is present in the .zip // file. This is similar to what git-merge does with `-srecursive -Xtheirs`. ZipMergeStrategyRecursiveTheirs )
func ParseZipMergeStrategy ¶ added in v1.3.0
func ParseZipMergeStrategy(name string) (ZipMergeStrategy, error)
ParseZipMergeStrategy returns the corresponding ZipMergeStrategy for the provided name.
func (ZipMergeStrategy) String ¶ added in v1.3.0
func (z ZipMergeStrategy) String() string