Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2022-2026 Salesforce, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

# Guard against committing directly to main
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" = "main" ]; then
echo "error: commits directly to main are not allowed. Use a development branch."
exit 1
fi

# Run linter on staged changes
cd "$(git rev-parse --show-toplevel)" || exit 1
go tool golangci-lint run
14 changes: 14 additions & 0 deletions .github/MAINTAINERS_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Certain things are common during development and require a few commands.
**Task outline:**

- [Cloning the project](#cloning-the-project)
- [Git hooks](#git-hooks)
- [Initializing the project](#initializing-the-project)
- [Testing](#testing)
- [Module and unit tests](#module-and-unit-tests)
Expand All @@ -233,6 +234,19 @@ git clone https://github.com/slackapi/slack-cli.git
cd slack-cli/
```

#### Git hooks

Opt-in Git hooks are available in the `.githooks/` directory. To enable them:

```zsh
git config core.hooksPath .githooks
```

The pre-commit hook will:

- Block commits directly to the `main` branch
- Run `go tool golangci-lint run` to lint before committing

### Initializing the project

When you first clone the project or after you major updates to the project, it's
Expand Down
Loading