diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..2ae0a3a --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,13 @@ +# Code of Conduct + +PiHoleShell follows the [Contributor Covenant, version 2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). + +In short: be respectful and constructive in issues, pull requests and discussions. Harassment, personal attacks, insulting or discriminatory comments, and publishing someone's private information aren't tolerated. + +## Reporting + +If someone's behaviour breaks this code, report it privately through the repository's [Security tab](https://github.com/mikemadeja/PiHoleShell/security) using **Report a vulnerability**, and say in the title that it's a conduct report. Only the maintainer can see it. Reports are kept confidential. + +## Enforcement + +The maintainer reviews every report and may edit or remove comments, close or lock threads, or block people from the project, depending on how serious the behaviour is. The Contributor Covenant's [enforcement guidelines](https://www.contributor-covenant.org/version/2/1/code_of_conduct/#enforcement-guidelines) are followed. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..c771c35 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,71 @@ +# Contributing to PiHoleShell + +Thanks for helping out! Bug reports, feature requests, docs fixes and pull requests are all welcome. + +## Reporting bugs and requesting features + +Use the [issue forms](https://github.com/mikemadeja/PiHoleShell/issues/new/choose). For bugs, please include your PiHoleShell, PowerShell and Pi-hole versions, the command you ran, and the full error. Remove your server address and password first. + +Found a security problem? Don't open a public issue. Follow the [security policy](SECURITY.md) instead. + +## Branches and pull requests + +- Branch from **`develop`** and open your pull request **into `develop`**. Never target `main`. +- `main` is the release branch. The maintainer promotes `develop` → `main`, and merging that PR publishes a new release automatically. +- Keep each PR to one feature or fix, and describe what changed and how you tested it. +- Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/): `feat:`, `fix:`, `docs:`, `test:`, `refactor:`, `ci:` or `chore:`. + +## Adding or changing a function + +1. **Check the real API first.** Your Pi-hole serves its own API docs at `https:///api/docs`. Confirm the endpoint's path, parameters and response fields there, not from similar functions. +2. **Put the function in its own file**, `PiHoleShell/Public//-PiHole.ps1`, using an [approved verb](https://learn.microsoft.com/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands). +3. **Use the standard parameters:** `PiHoleServer`, `Password`, `IgnoreSsl` and, for functions that return data, `RawOutput`. +4. **Call the API through `Invoke-PiHoleApiRequest`.** This private helper handles login, the request and logout. Don't copy that block into your function: SonarCloud fails the build when more than 3% of new code is duplicated. +5. **Report errors through the friendly message helper:** + + ```powershell + catch { + Write-Error -Message (ConvertTo-PiHoleFriendlyErrorMessage -ErrorRecord $_) + } + ``` + +6. **Write comment-based help** with `.SYNOPSIS`, `.DESCRIPTION`, every `.PARAMETER`, at least one `.EXAMPLE`, and a `HelpUri` pointing at the endpoint in Pi-hole's API docs. +7. **Export the function** in both places: + - the `Export-ModuleMember` list in `PiHoleShell/PiHoleShell.psm1` + - `FunctionsToExport` in `PiHoleShell/PiHoleShell.psd1`. This file is saved as UTF-16; keep that encoding when you edit it. +8. **Update the docs:** + - Run `tools/Update-ReadmeCommandReference.ps1` to regenerate the README's command reference. A CI check fails if it's out of date. + - Add an entry to `tools/Update-ExampleOutput.ps1`, then run it to regenerate `docs/EXAMPLES.md`. This step needs a test server. + +`Get-PiHoleApiEndpoint` (`PiHoleShell/Public/FTLInformation/Get-PiHoleApiEndpoint.ps1`) is a short, complete example that follows all of these. + +## Tests + +Tests use [Pester 5](https://pester.dev/) and live under `tests/`, in the same area folders as the functions. + +- **Unit tests** (`*.Tests.ps1`) mock the API and run anywhere: + + ```powershell + Invoke-Pester -Path .\tests -ExcludeTagFilter Integration + ``` + +- **Integration tests** (`*.Integration.Tests.ps1`) call a real Pi-hole. Copy `tests/IntegrationConfig.example.ps1` to `tests/IntegrationConfig.local.ps1` (it's gitignored) and fill in your server and app password. Then run: + + ```powershell + Invoke-Pester -Path .\tests -TagFilter Integration + ``` + + Some integration tests make real changes, like rebuilding gravity, restarting DNS and flushing logs. Point them at a test instance, not your production Pi-hole. + +New functions should come with an integration test covering normal output, `-RawOutput $true`, and a bad password. + +## Checks on your pull request + +- **PSScriptAnalyzer** must report no issues. Run it locally with `Invoke-ScriptAnalyzer -Path .\PiHoleShell -Recurse`. +- **SonarCloud** must pass its quality gate. In practice that usually means not duplicating code. +- **README sync** must pass (see step 8 above). +- **Pester** integration tests run against the maintainer's own Pi-hole and can take up to an hour. If your PR comes from a fork, the maintainer may run them for you. + +## Code of conduct + +Everyone taking part is expected to follow the [code of conduct](CODE_OF_CONDUCT.md). diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..9b70aea --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,63 @@ +name: Bug report +description: A PiHoleShell command doesn't work as expected +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for reporting! **Remove your server address, password and session IDs** from anything you paste below. + Found a security problem? Please report it privately instead. See the security policy. + - type: input + id: command + attributes: + label: Command + description: Which PiHoleShell command has the problem? + placeholder: Get-PiHoleStatsSummary + validations: + required: true + - type: textarea + id: repro + attributes: + label: What you ran + description: The exact command and parameters, with your server and password replaced. + render: powershell + validations: + required: true + - type: textarea + id: expected + attributes: + label: What you expected + validations: + required: true + - type: textarea + id: actual + attributes: + label: What happened + description: The output or the full error message. Running the command with `-Verbose` often helps. + render: text + validations: + required: true + - type: input + id: module-version + attributes: + label: PiHoleShell version + description: Output of `(Get-Module PiHoleShell -ListAvailable).Version` + placeholder: 1.2.0 + validations: + required: true + - type: input + id: ps-version + attributes: + label: PowerShell version and OS + description: Output of `$PSVersionTable.PSVersion`, plus your operating system + placeholder: 7.5.2 on Windows 11 + validations: + required: true + - type: input + id: pihole-version + attributes: + label: Pi-hole version + description: Output of `Get-PiHoleInfoVersion`, or the versions shown at the bottom of the Pi-hole web page + placeholder: Core v6.5, FTL v6.8, Web v6.6.1 + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..c928b97 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Report a security vulnerability + url: https://github.com/mikemadeja/PiHoleShell/security/advisories/new + about: Please report security problems privately, not as a public issue. + - name: Problem with Pi-hole itself + url: https://discourse.pi-hole.net/ + about: For problems with Pi-hole rather than this PowerShell module, ask the Pi-hole community. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..5ff1c87 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,24 @@ +name: Feature request +description: Suggest a new command or an improvement to an existing one +labels: ["enhancement"] +body: + - type: textarea + id: goal + attributes: + label: What do you want to do? + description: Describe the task you're trying to get done, not just the solution. + placeholder: I want to export all my local DNS records to a CSV so I can copy them to a second Pi-hole. + validations: + required: true + - type: textarea + id: proposal + attributes: + label: Suggested command or change + description: Optional. What should it look like? Include an example call if you can. + render: powershell + - type: input + id: endpoint + attributes: + label: Pi-hole API endpoint + description: Optional. The endpoint involved, if you know it (see `https:///api/docs`). + placeholder: GET /api/config/dns/hosts diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..f81b9f2 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,27 @@ +# Security Policy + +## Supported versions + +Only the latest release on the [PowerShell Gallery](https://www.powershellgallery.com/packages/PiHoleShell) gets security fixes. Update with `Update-Module PiHoleShell` before reporting. + +## Reporting a vulnerability + +**Please don't open a public issue for security problems.** + +Report them privately through GitHub: open the repository's [Security tab](https://github.com/mikemadeja/PiHoleShell/security) and click **Report a vulnerability**. Only the maintainer can see the report. + +Please include: + +- what the problem is and what someone could do with it +- steps to reproduce, with your PiHoleShell, PowerShell and Pi-hole versions +- any fix you'd suggest + +Never include a real password, app password or session ID. + +This is a spare-time project, so there's no guaranteed response time, but security reports are dealt with first. Once a fix is released, the report can be published with credit to you, if you'd like. + +## Scope + +This policy covers the PiHoleShell module itself, for example leaking credentials or session IDs, or sending them somewhere they shouldn't go. Vulnerabilities in Pi-hole itself should go to the [Pi-hole project](https://github.com/pi-hole/pi-hole/security). + +Note that `-IgnoreSsl $true` turns off certificate checking on purpose, for servers with self-signed certificates. That's not a vulnerability, but avoid it on networks you don't trust. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..048765f --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,16 @@ +## What this changes + + + +## How it was tested + + + +## Checklist + +- [ ] This PR targets `develop`, not `main` +- [ ] New or changed functions call the API through `Invoke-PiHoleApiRequest` and have comment-based help +- [ ] New functions are exported in both `PiHoleShell.psm1` and `PiHoleShell.psd1` +- [ ] Tests were added or updated, and they pass +- [ ] `Invoke-ScriptAnalyzer -Path .\PiHoleShell -Recurse` reports nothing +- [ ] README command reference regenerated with `tools/Update-ReadmeCommandReference.ps1`, if functions were added or renamed diff --git a/README.md b/README.md index 5bbf16d..04ab700 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ The module ships with two kinds of [Pester](https://pester.dev/) tests under `te ## Contributing -This project is still early and growing. Issues, suggestions, and pull requests are welcome — see the 🚧 items in the [Command Reference](#command-reference) above for functions that could use testing or polish. +Issues, suggestions, and pull requests are welcome. See the [contributing guide](.github/CONTRIBUTING.md) for how to add a function, run the tests and open a pull request. Please report security problems privately, as described in the [security policy](.github/SECURITY.md). ## License