Skip to content

Commit

Permalink
Hound search main (#16)
Browse files Browse the repository at this point in the history
* Update config-example.json

* Add CONTRIBUTING.md file

* Dockerfile should use github.com/hound-search

This fixing the docker build issue.

* make listen URL clickable in iTerm (hound-search#340)

* Add Jest tests and Prettier support (hound-search#343)

This commit adds support for Jest and writes a few simple tests as
proof. Adding a test is as easy as adding a file that ends in
`.test.js` next to the file you want to test. Any file that matches that
pattern should have access to Jest functions. The whole test suite can
be run with `npm run test`.

I also added support for Prettier. Running `npm run format`
should run Prettier on any staged changes. I thought about adding Husky
to automatically run Prettier as a pre-commit hook, but it seems as
though Husky requires git v2.13 which would require me upgrading Git.

I didn't add support for ESLint yet since I figured that may be a
slightly more involved conversation — Prettier seems to be generally
uncontroverical and is generally only slightly configurable, whereas
ESlint is highly configurable and behaves however we want it to.

* Git VCS driver: Support non-default target refs (hound-search#345)

Currently, only the default ref (`master`) is supported.

- Allow target non-default target refs to be specified via configs.
- Add config-driven target ref auto-detection using the `HEAD` branch.
- Update default repo base URL pattern to link to the content revision,
  accounting for potential non-default target ref usage.
- Add global-level VCS configs which are merged into the repo-level configs
  during startup (repo-level vals take precedence).

* Exclude file path (hound-search#347)

* index: add a search option to exclude files given a regexp

* api: add the excludeFiles query parameter

Set the index search options ExcludeFileRegexp with this parameter
to allow excluding files from the search via a regexp.

* js: add the excludeFiles search parameter

* css: increase the label width to fit 'Exclude file path'

* js: correctly check that advanced is empty

* Update README with contact info for maintainers. (hound-search#348)

I don't think there's a clear way to see who has push privs to this repo from the public, and even if there is, the "Get In Touch" section should probably list the maintainers.

* incorporate detailing around gopath in README's quick start instructions (hound-search#352)

Co-authored-by: Rebecca Lau <blobbered@users.noreply.github.com>

* pin alpine version to make the docker pass

* Update Dockerfile

* More detailed setup documents with less assumptions on users (hound-search#359)

This commit updates the readme to be a little more verbose for people who don't necessarily have Go or Docker set up, but who want to contribute nonetheless. 

* Apply the old patch

* add  some figures

* remove the idea code

* get it untitled

* remove

* add .idea dev tools

* remove simple config

* get config back

* detailing tests and simplifying the setup

* Commit TLS support guide

Co-authored-by: Salem <salemhilal@gmail.com>

* make the statement terser

* delete unused img

* rewording

* back to the old path

* Update README.md

* Update README.md

* Update README.md

* Update README.md

Co-authored-by: Salem <salemhilal@gmail.com>

* Initialize Go Modules

`go mod init github.com/hound-search/hound`

* Replace jteeuwen/go-bindata with go-bindata/go-bindata

The former package is unmainatained since a while and the replacement
also fixes this bug I encountered when trying to build the package:
jteeuwen/discussions#6

* update Go version requirement in README file

* Add a -version flag to Houndd (hound-search#362)

This commit adds a `-version` flag to houndd. Running `houndd -version` prints the current version and exits.

Co-authored-by: Kartikay Shandil <kartikays@sahaj.ai>

* Add padding between advanced mode text inputs

* add margin bottom to fields that are not last

* update front end bundles

Co-authored-by: Blobb Ered <@blobbered>

* Setup Github Actions CI (hound-search#354)

* Setup Github Actions CI

Replaces Travis CI with Github Actions for better integration.
Jobs are run against more recent Go versions, namely 1.12 to 1.14 .
 .
For further documentation see

- https://github.com/actions/setup-go
- and https://help.github.com/en/actions

This adds `-race` flag to the Go tests and will run a meta linter
(golangci-lint).

* keep travis in until github workflows is tested

* tidy go mods

* remove lint command from github workflow

* add back go-bindata to go modules list

* up version of actions checkout to fix deprecation errors

* return go bindata to the go.sum file as well

Co-authored-by: Andreas Linz <anli@spreadshirt.net>

* Add a github actions badge

Thanks again @klingtnet and @blobbered for making this possible!

* Update README.md (hound-search#369)

Add clarification of using file:// protocol for accessing locally pulled repos

* Added new folder docs with config-options description on options. (hound-search#370)

* Added new folder docs with config-options description on options.

* Peer review comment update
updated formatting for config options documentation and added link
in readme.

* readme link update

* link update

* Minor edits from code review

Co-authored-by: kayyapil <k.ayyapillai@reply.com>
Co-authored-by: ehrktia <a.karthie+github@pm.me>
Co-authored-by: Salem <salemhilal@gmail.com>

* Test windows

* Run Go build and test on Ubuntu Linux and Windows

* Add lint

* Install dependencies in Dockerfile

* Fix typo

* Adding a tip for windows users (hound-search#379)

* Adding a tip for windows users

* Update README.md

Co-authored-by: Salem <salemhilal@gmail.com>

Co-authored-by: Salem <salemhilal@gmail.com>

* Use tini as default entry point (hound-search#376)

* Add a warning for the default branch rename (hound-search#380)

* Add a warning for the default branch rename

* Add a link to Github's renaming documentation.

* Update README to reflect branch rename. (hound-search#384)

* Update version in main.go

* support github webhook

* Omit ports in constructed URL (hound-search#383)

* Improve accessibility (hound-search#398)

* Resolve WCAG2AA.Principle3.Guideline3_1.3_1_1.H57.2

* Resolve WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.InputText.Name

* Resolve WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.Button.Name

* Improve stats contrast

* Improve advanced text contrast

* Improve repo title contrast

* Improve contrast in advanced section

* Improve line number contrast

* Improve excluded files contrast

* Improve "load all" button contrast

* Automatically build docker image and publish to ghcr.io (hound-search#401)

* Feat: Use goreleaser

* Feat: Add docker build, remove goreleaser

* Fix: Add image name

* Feat: Use ghcr.io and build-push-action@2

* We try again

* Trying yet again

* Fix: Use actor and GITHUB_TOKEN

* Fix: Use github.actor in image tag path

* Fix: use github.repository_owner instead of github.actor

When you have an organisation, github.actor != github.repository_owner

Co-authored-by: Jone Marius Vignes <jvig@ihelse.net>

* Update default-config.json (hound-search#391)

* Update default-config.json

* Update default-config.json (ref: main)

* Add hyperlinks to repository root (hound-search#396)

* Add literal search option (hound-search#397)

* Add literal search option

* Pull EscapeRegExp into common.js

* Add db/ to Jest ignore patterns

* Test EscapeRegExp() matches its input

* Test vacuous EscapeRegExp

* Give repo links a target of blank (hound-search#404)

Add rel="noopener noreferrer" to _blank links

Co-authored-by: Joseph Price <pricejosephd@gmail.com>
Co-authored-by: dschott <dschott@etsy.com>
Co-authored-by: Nicolas R <cpan@atoomic.org>
Co-authored-by: Igor <igorwwwwwwwwwwwwwwwwwwww@users.noreply.github.com>
Co-authored-by: Salem <salemhilal@gmail.com>
Co-authored-by: Richard Liang <rwliang@users.noreply.github.com>
Co-authored-by: Vincent Rischmann <vincent@rischmann.fr>
Co-authored-by: Blobb Ered <5307533+blobbered@users.noreply.github.com>
Co-authored-by: Rebecca Lau <blobbered@users.noreply.github.com>
Co-authored-by: Ruixi Fan <rfan@etsy.com>
Co-authored-by: Ruixi Fan <69488297+rfan-debug@users.noreply.github.com>
Co-authored-by: Andreas Linz <anli@spreadshirt.net>
Co-authored-by: Rebecca Lau <rblau@etsy.com>
Co-authored-by: Kartikay Shandil <shandilkartikay@gmail.com>
Co-authored-by: Kartikay Shandil <kartikays@sahaj.ai>
Co-authored-by: Ashley Roach <aroach@gmail.com>
Co-authored-by: karthick <a.karthie+github@gmail.com>
Co-authored-by: kayyapil <k.ayyapillai@reply.com>
Co-authored-by: ehrktia <a.karthie+github@pm.me>
Co-authored-by: David Kolossa <david.kolossa@posteo.de>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Andrew Stanton <StingyJack@users.noreply.github.com>
Co-authored-by: David Schott <dschott68@users.noreply.github.com>
Co-authored-by: Cor Bosman <cor@xs4all.net>
Co-authored-by: Jacob Rose <jacob@usroses.org>
Co-authored-by: Alexander Chiu <alexanderchiu@users.noreply.github.com>
Co-authored-by: Joel Armstrong <mrjoelarmstrong@gmail.com>
Co-authored-by: Jone Marius Vignes <73816+inful@users.noreply.github.com>
Co-authored-by: Jone Marius Vignes <jvig@ihelse.net>
Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
Co-authored-by: Bucky Schwarz <hoorayimhelping@users.noreply.github.com>
  • Loading branch information
1 parent f80e3d2 commit 56f53b0
Show file tree
Hide file tree
Showing 44 changed files with 5,490 additions and 269 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/go.yaml
@@ -0,0 +1,81 @@
on: [push]
jobs:
go-build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.14", "1.13", "1.12"]
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go build -x -work ./cmds/...
node-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-node@v1
with:
node-version: "10.x"
- run: npm install
docker-build:
name: Create docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/${{ github.repository_owner }}/hound
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub Packages
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.prep.outputs.tags }}
golangci:
name: lint
strategy:
matrix:
go: ["1.14"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.3.4
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.3.0
with:
# the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.35.2
go-test:
strategy:
matrix:
go: ["1.14", "1.13", "1.12"]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go test -race ./...
# There are no npm tests, yet.
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
ui/assets/js/JSXTransformer-0.12.2.js
ui/assets/js/jquery-2.1.3.min.js
ui/assets/js/react-0.12.2.min.js
3 changes: 3 additions & 0 deletions .prettierrc
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,19 @@
# Contributing to Hound
We welcome (and appreciate) contributions from the community! Give this guide a quick read to ensure your contribution
goes as smoothly as possible.

## Submitting contributions
If you're just getting started, this guide will help get you started
[hacking on hound](https://github.com/hound-search/hound#hacking-on-hound).

Once you're ready, open a [pull request](https://github.com/hound-search/hound/compare) with a clear description of
your changes (you can read more about pull requests on GitHub [here](http://help.github.com/pull-requests/)).

When you send a pull request, please be sure to include:
- unit tests that validate that your changes work as expected (both for Go and for JavaScript changes)
- consice code comments (it can help to imagine that you're explaining your code to a total stranger)
- an examples, if necessary.

## More
Hound is a volunteer effort. We do our best to try and review contributions in a timely manner. Any code or feedback
you share with us is hugely appreciated.
14 changes: 7 additions & 7 deletions Dockerfile
@@ -1,14 +1,14 @@
FROM alpine
FROM alpine:3.11.7

ENV GOPATH /go

COPY . /go/src/github.com/etsy/hound

COPY default-config.json /data/config.json
COPY . /go/src/github.com/hound-search/hound

RUN apk update \
&& apk add go git subversion libc-dev mercurial bzr openssh \
&& go install github.com/etsy/hound/cmds/houndd \
&& apk add go git subversion libc-dev mercurial bzr openssh tini \
&& cd /go/src/github.com/hound-search/hound \
&& go mod download \
&& go install github.com/hound-search/hound/cmds/houndd \
&& apk del go \
&& rm -f /var/cache/apk/* \
&& rm -rf /go/src /go/pkg
Expand All @@ -17,4 +17,4 @@ VOLUME ["/data"]

EXPOSE 6080

ENTRYPOINT ["/go/bin/houndd", "-conf", "/data/config.json"]
ENTRYPOINT ["/sbin/tini", "--", "/go/bin/houndd", "-conf", "/data/config.json"]
11 changes: 9 additions & 2 deletions Makefile
Expand Up @@ -21,8 +21,7 @@ $(GOPATH)/bin/hound: ui/bindata.go $(SRCS)
go install github.com/hound-search/hound/cmds/hound

.build/bin/go-bindata:
$(GOPATH)/bin/go-bindata.exe
#GOPATH=`pwd`/.build go get github.com/jteeuwen/go-bindata/...
GOPATH=`pwd`/.build go get github.com/go-bindata/go-bindata/...

ui/bindata.go: $(GOPATH)/bin/go-bindata.exe node_modules $(wildcard ui/assets/**/*)
mkdir .build\ui
Expand All @@ -35,6 +34,14 @@ dev: ALL

test:
go test github.com/hound-search/hound/...
npm test

lint:
export GO111MODULE=on
go get github.com/golangci/golangci-lint/cmd/golangci-lint
export GOPATH=/tmp/gopath
export PATH=$GOPATH/bin:$PATH
golangci-lint run ./...

clean:
rmdir /s /q .build node_modules
75 changes: 62 additions & 13 deletions README.md
@@ -1,63 +1,93 @@
# Hound

[![Build Status](https://travis-ci.org/hound-search/hound.svg?branch=master)](https://travis-ci.org/hound-search/hound)
[![Build Status](https://travis-ci.org/hound-search/hound.svg?branch=master)](https://travis-ci.org/hound-search/hound)
[![.github/workflows/go.yaml](https://github.com/hound-search/hound/workflows/.github/workflows/go.yaml/badge.svg)](https://github.com/hound-search/hound/actions)

> ## :warning: Hound's default branch name has changed! :warning:
> **We renamed our default branch from `master` to `main` on February 24, 2021**. We used [Github's branch renaming feature](https://github.com/github/renaming/#renaming-existing-branches), which means that any open pull requests should be automatically re-targeted, and web requests pointing to code on the `master` branch should redirect as expected. This change should mostly be invisible, but you will need to update any code that explicitly relies on the existence of Hound's `master` branch.
Hound is an extremely fast source code search engine. The core is based on this article (and code) from Russ Cox:
[Regular Expression Matching with a Trigram Index](http://swtch.com/~rsc/regexp/regexp4.html). Hound itself is a static
[React](http://facebook.github.io/react/) frontend that talks to a [Go](http://golang.org/) backend. The backend keeps an up-to-date index for each repository and answers searches through a minimal API. Here it is in action:

![Hound Screen Capture](screen_capture.gif)
![Hound Screen Capture](imgs/screen_capture.gif)

## Quick Start Guide

### Using Go Tools

1. Use the Go tools to install Hound. The binaries `houndd` (server) and `hound` (cli) will be installed in your $GOPATH.

0. [Install Go](https://golang.org/doc/install) if you don't have it already. Hound requires version 1.4 or later.
You might also want to define a [`GOPATH`](https://github.com/golang/go/wiki/GOPATH) environment variable)
(it defaults to $HOME/go if you don't explicitly have one set). If everything is installed properly, `go version` should
print out the installed version of go.

1. Use the Go tools to install Hound. The binaries `houndd` (server) and `hound` (cli) will be installed in your $GOPATH/bin directory. Your $GOPATH should be in your $PATH (`echo $PATH` to check).


```
go get github.com/hound-search/hound/cmds/...
```

2. Create a [config.json](config-example.json) in a directory with your list of repositories.
2. Create a config.json file and use it to list your repositories. Check out our [example-config.json](config-example.json)
to see how to set up various types of repositories. For example, we can configure Hound to search its own source code using
the config found in [default-config.json](default-config.json):

3. Run the Hound server with `houndd` and you should see output similar to:
```json
{
"dbpath" : "db",
"repos" : {
"Hound" : { "url" : "https://github.com/etsy/hound.git" }
}
}
```


A complete list of available config options can be found [here](docs/config-options.md).
3. Run the Hound server with `houndd` in the same directory as your `config.json`. You should see output similar to:
```
2015/03/13 09:07:42 Searcher started for statsd
2015/03/13 09:07:42 Searcher started for Hound
2015/03/13 09:07:42 All indexes built!
2015/03/13 09:07:42 running server at http://localhost:6080...
2015/03/13 09:07:42 running server at http://localhost:6080
```

4. By default, hound hosts a web ui at http://localhost:6080 . Open it in your browser, and start searching.

### Using Docker (1.4+)

1. Create a [config.json](config-example.json) in a directory with your list of repositories.
0. [Install the docker](https://docs.docker.com/get-docker/) if you don't have it. We need at least `Docker >= 1.14`.

1. Create a config.json file and use it to list your repositories. Check out our [example-config.json](config-example.json)
to see how to set up various types of repositories. For example, we can configure Hound to search its own source code using
the config found in [default-config.json](default-config.json).

2. Run
```
docker run -d -p 6080:6080 --name hound -v $(pwd):/data etsy/hound
```

You should be able to navigate to [http://localhost:6080/](http://localhost:6080/) as usual.

You should be able to navigate to [http://localhost:6080/](http://localhost:6080/) as usual.

## Running in Production

There are no special flags to run Hound in production. You can use the `--addr=:6880` flag to control the port to which the server binds. Currently, Hound does not support TLS as most users simply run Hound behind either Apache or nginx. Adding TLS support is pretty straight forward though if anyone wants to add it.
There are no special flags to run Hound in production. You can use the `--addr=:6880` flag to control the port to which the server binds.
Currently, Hound does not support TLS as most users simply run Hound behind either Apache or nginx. However, we are open to contributions to add TLS support.

## Why Another Code Search Tool?

We've used many similar tools in the past, and most of them are either too slow, too hard to configure, or require too much software to be installed.
Which brings us to...

## Requirements
* Go 1.4+
* Go 1.13+

Yup, that's it. You can proxy requests to the Go service through Apache/nginx/etc., but that's not required.


## Support

Currently Hound is only tested on MacOS and CentOS, but it should work on any *nix system. Hound on Windows is not supported but we've heard it compiles and runs just fine.
Currently Hound is only tested on MacOS and CentOS, but it should work on any *nix system. Hound on Windows is not supported but we've heard it compiles and runs just fine (although it helps to to exclude your data folder from Windows Search Indexer).

Hound supports the following version control systems:

Expand All @@ -73,7 +103,7 @@ See [config-example.json](config-example.json) for examples of how to use each V
There are a couple of ways to get Hound to index private repositories:

* Use the `file://` protocol. This allows you to index a local clone of a repository. The downside here is that the polling to keep the repo up to date will
not work. (This also doesn't work on local folders that are not of a supported repository type.)
not work. (This also doesn't work on local folders that are not of a supported repository type.) If you're using Docker, you must mount a volume to your repository (e.g., `-v $(pwd)/src:/src`) and use the relative path to the repo in your configuration.
* Use SSH style URLs in the config: `"url" : "git@github.com:foo/bar.git"`. As long as you have your
[SSH keys](https://help.github.com/articles/generating-ssh-keys/) set up on the box where Hound is running this will work.

Expand Down Expand Up @@ -117,11 +147,23 @@ GOPATH=$(pwd) make -C src/github.com/hound-search/hound
### Testing

There are an increasing number of tests in each of the packages in Hound. Please make sure these pass before uploading your Pull Request. You can run the tests with the following command.
To run the entire test suite, use:

```
make test
```

If you want to just run the JavaScript test suite, use:
```
npm test
```

Any Go files that end in `_test.go` are assumed to be test files. Similarly, any JavaScript files that ends in `.test.js` are automatically run by Jest, our test runner. Tests should live next to the files that they cover.
[Check out Jest's docs](https://jestjs.io/docs/en/getting-started) for more details on writing Jest tests,
and [check out Go's testing docs](https://golang.org/pkg/testing/) for more details on testing Go code.

You need to install `Node.js >= 12` and install `jest` by `npm install jest` to run the JS tests.

### Working on the web UI

Hound includes a web UI that is composed of several files (html, css, javascript, etc.). To make sure hound works seamlessly with the standard Go tools, these resources are all bundled inside of the `houndd` binary. Note that changes to the UI will result in local changes to the `ui/bindata.go` file. You must include these changes in your Pull Request.
Expand Down Expand Up @@ -152,3 +194,10 @@ Created at [Etsy](https://www.etsy.com) by:

* [Kelly Norton](https://github.com/kellegous)
* [Jonathan Klein](https://github.com/jklein)

Hound is maintained by:

* [David Schott](https://github.com/dschott68)
* [Jacob Rose](https://github.com/jacobrose)
* [Nick Sawyer](https://github.com/nickmoorman)
* [Salem Hilal](https://github.com/salemhilal)
2 changes: 1 addition & 1 deletion ansi/ansi_test.go
Expand Up @@ -11,7 +11,7 @@ var (
printTests = false
)

func makeReal(s string) string {
func makeReal(s string) string { //nolint
return strings.Replace(s, "~", "\x1b", -1)
}

Expand Down
2 changes: 1 addition & 1 deletion ansi/tty_linux.go
@@ -1,4 +1,4 @@
package ansi

const ioctlReadTermios = 0x5401 // syscall.TCGETS
const ioctlWriteTermios = 0x5402 // syscall.TCSETS
const ioctlWriteTermios = 0x5402 //nolint syscall.TCSETS
51 changes: 50 additions & 1 deletion api/api.go
Expand Up @@ -89,7 +89,7 @@ func searchAll(
*filesOpened += r.res.FilesOpened
}

*duration = int(time.Now().Sub(startedAt).Seconds() * 1000)
*duration = int(time.Now().Sub(startedAt).Seconds() * 1000) //nolint

return res, nil
}
Expand Down Expand Up @@ -178,7 +178,9 @@ func Setup(m *http.ServeMux, idx map[string]*searcher.Searcher) {
query := r.FormValue("q")
opt.Offset, opt.Limit = parseRangeValue(r.FormValue("rng"))
opt.FileRegexp = r.FormValue("files")
opt.ExcludeFileRegexp = r.FormValue("excludeFiles")
opt.IgnoreCase = parseAsBool(r.FormValue("i"))
opt.LiteralSearch = parseAsBool(r.FormValue("literal"))
opt.LinesOfContext = parseAsUintValue(
r.FormValue("ctx"),
0,
Expand Down Expand Up @@ -249,4 +251,51 @@ func Setup(m *http.ServeMux, idx map[string]*searcher.Searcher) {

writeResp(w, "ok")
})

m.HandleFunc("/api/v1/github-webhook", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
writeError(w,
errors.New(http.StatusText(http.StatusMethodNotAllowed)),
http.StatusMethodNotAllowed)
return
}

type Webhook struct {
Repository struct {
Name string
Full_name string
}
}

var h Webhook

err := json.NewDecoder(r.Body).Decode(&h)

if err != nil {
writeError(w,
errors.New(http.StatusText(http.StatusBadRequest)),
http.StatusBadRequest)
return
}

repo := h.Repository.Full_name

searcher := idx[h.Repository.Full_name]

if searcher == nil {
writeError(w,
fmt.Errorf("No such repository: %s", repo),
http.StatusNotFound)
return
}

if !searcher.Update() {
writeError(w,
fmt.Errorf("Push updates are not enabled for repository %s", repo),
http.StatusForbidden)
return
}

writeResp(w, "ok")
})
}

0 comments on commit 56f53b0

Please sign in to comment.