gitserver

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: BSD-3-Clause Imports: 35 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,
	zipMergeStrategy ZipMergeStrategy,
	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,
	zipMergeStrategy ZipMergeStrategy,
	repo *git.Repository,
	parent *git.Oid,
	author, committer *git.Signature,
	commitMessage string,
	w io.Writer,
	log log15.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 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 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.

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,
	zipReader *zip.Reader,
	authorizationLevel githttp.AuthorizationLevel,
	repo *git.Repository,
	lockfile *githttp.Lockfile,
	authorUsername string,
	commitMessage string,
	problemSettings *common.ProblemSettings,
	zipMergeStrategy ZipMergeStrategy,
	acceptsSubmissions bool,
	protocol *githttp.GitProtocol,
	log log15.Logger,
) (*UpdateResult, error)

PushZip reads the contents of the .zip file pointed at to by zipReader, creates a packfile out of it, and pushes it to the master branch of the repository.

type UpdatedFile added in v1.3.0

type UpdatedFile struct {
	Path string `json:"path"`
	Type string `json:"type"`
}

UpdatedFile represents an updated file. Type is either "added", "deleted", or "modified".

func GetUpdatedFiles added in v1.3.0

func GetUpdatedFiles(
	repo *git.Repository,
	updatedRefs []githttp.UpdatedRef,
) ([]UpdatedFile, error)

GetUpdatedFiles returns the files that were updated in the master branch.

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

Jump to

Keyboard shortcuts

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