gitserver

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2018 License: BSD-3-Clause Imports: 34 Imported by: 0

README

gitserver

Documentation Go Report Card Build status

The omegaUp Git server for problems.

Documentation

Index

Constants

View Source
const (

	// OverallWallTimeHardLimit is the absolute maximum wall time that problems
	// are allowed to have.
	OverallWallTimeHardLimit = common.Duration(time.Duration(60) * time.Second)
)

Variables

View Source
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")

	// 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")

	// 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(/[^/]+\\.(markdown|gif|jpe?g|png))?$"),
				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(/[^/]+\\.(markdown|gif|jpe?g|png))?$"),
				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$"),
			},
		},
	}
)
View Source
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

func ConvertMarkdownToUTF8(r io.Reader) (io.Reader, error)

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(
	zipReader *zip.Reader,
	settings *common.ProblemSettings,
	updateMask ConvertZipUpdateMask,
	repo *git.Repository,
	parent *git.Oid,
	author, committer *git.Signature,
	commitMessage string,
	acceptsSubmissions bool,
	w io.Writer,
	log log15.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(
	contents map[string]io.Reader,
	settings *common.ProblemSettings,
	updateMask ConvertZipUpdateMask,
	repo *git.Repository,
	parent *git.Oid,
	author, committer *git.Signature,
	commitMessage string,
	w io.Writer,
	log log15.Logger,
) (*git.Oid, error)

func GitHandler

func GitHandler(
	rootPath string,
	protocol *githttp.GitProtocol,
	log log15.Logger,
) http.Handler

GitHandler is the HTTP handler for the omegaUp git server.

func InitRepository

func InitRepository(
	repositoryPath string,
) (*git.Repository, error)

InitRepository is a wrapper around git.CreateRepository() that also adds omegaUp-specific files to the repository.

func NewGitProtocol

func NewGitProtocol(
	authCallback githttp.AuthorizationCallback,
	referenceDiscoveryCallback githttp.ReferenceDiscoveryCallback,
	allowDirectPushToMaster bool,
	hardOverallWallTimeLimit common.Duration,
	interactiveSettingsCompiler InteractiveSettingsCompiler,
	log log15.Logger,
) *githttp.GitProtocol

NewGitProtocol creates a new GitProtocol with the provided authorization callback.

func NormalizeCase

func NormalizeCase(r io.Reader) (io.Reader, error)

NormalizeCase performs a best-effort conversion to UTF-8 and normalizes the end-of-line characters.

func ZipHandler

func ZipHandler(
	rootPath string,
	protocol *githttp.GitProtocol,
	log log15.Logger,
) http.Handler

ZipHandler is the HTTP handler that allows uploading .zip files.

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 Config

type Config struct {
	Publishing PublishingConfig `json:"publishing"`
}

Config represents the contents of config.json in refs/meta/config.

type ConvertZipUpdateMask

type ConvertZipUpdateMask int

A ConvertZipUpdateMask represents a bitfield of elements that will be extracted from the .zip file and updated in the git branch.

const (
	// ConvertZipUpdateStatements will extract the contents of the statements/
	// directory.
	ConvertZipUpdateStatements ConvertZipUpdateMask = 1 << iota
	// ConvertZipUpdateNonStatements will extract everything that is not in the
	// statements/ directory.
	ConvertZipUpdateNonStatements
	// ConvertZipUpdateAll extracts all entries from the .zip file.
	ConvertZipUpdateAll = ConvertZipUpdateStatements | ConvertZipUpdateNonStatements
)

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 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                   log15.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.

func (*LineEndingNormalizer) Read

func (n *LineEndingNormalizer) Read(p []byte) (int, error)

Read implements io.Reader.

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.

Jump to

Keyboard shortcuts

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