<!--
SPDX-FileCopyrightText: Amolith <amolith@secluded.site>

SPDX-License-Identifier: CC0-1.0
-->

# go-lunatask

[![Godocs.io Reference](https://godocs.io/git.secluded.site/go-lunatask?status.svg)][godocs.io]
[![Pkg.go.dev Reference](https://pkg.go.dev/badge/git.secluded.site/go-lunatask.svg)][pkg.go.dev]
[![Go Report Card](https://goreportcard.com/badge/git.secluded.site/go-lunatask)](https://goreportcard.com/report/git.secluded.site/go-lunatask)
![Test coverage](https://img.shields.io/badge/coverage-84.9%25-brightgreen)
[![REUSE compatibility](https://api.reuse.software/badge/git.secluded.site/go-lunatask)](https://api.reuse.software/info/git.secluded.site/go-lunatask)
[![Liberapay donation status](https://img.shields.io/liberapay/receives/Amolith.svg?logo=liberapay)](https://liberapay.com/Amolith/)

[godocs.io]: https://godocs.io/git.secluded.site/go-lunatask
[pkg.go.dev]: https://pkg.go.dev/git.secluded.site/go-lunatask

Go client library for [Lunatask]'s [public API].

[Lunatask]: https://lunatask.app
[public API]: https://lunatask.app/api

[lune](https://git.secluded.site/lune), a CLI and MCP server for Lunatask, is
this library's primary consumer.

## Usage

Generate an access token in the Lunatask desktop app under `Settings` →
`Access tokens`.

```sh
go get git.secluded.site/go-lunatask@latest
```

See the module documentation on [godocs.io] or [pkg.go.dev] for more
detail.

```go
package main

import (
	"context"
	"log"
	"os"

	"git.secluded.site/go-lunatask"
)

func main() {
	client := lunatask.NewClient(os.Getenv("LUNATASK_TOKEN"), lunatask.UserAgent("MyApp/1.0"))

	// Verify credentials
	if _, err := client.Ping(context.Background()); err != nil {
		log.Fatal(err)
	}

	// Create a task
	task, err := client.NewTask("Review pull requests").Create(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	if task == nil {
		log.Println("Task already exists")
	}
}
```

### A note on duplicate handling

Create methods return `(nil, nil)` when a matching entity already
exists. This is intentional API behavior on Lunatask's part because of
its end-to-end encryption.

```go
task, err := client.NewTask("Review PR").Create(ctx)
if err != nil {
    return err // actual error
}
if task == nil {
    // duplicate exists, not created
}
```

## Contributions

Patch requests are in [amolith/go-lunatask] on [pr.pico.sh]. You don't
need a new account to contribute, you don't need to fork this repo, you
don't need to fiddle with `git send-email`, you don't need to faff with
your email client to get `git request-pull` working...

You just need:

- Git
- SSH
- An SSH key

```sh
# Clone this repo, make your changes, and commit them
# Create a new patch request with
git format-patch origin/main --stdout | ssh pr.pico.sh pr create amolith/go-lunatask
# After potential feedback, submit a revision to an existing patch request with
git format-patch origin/main --stdout | ssh pr.pico.sh pr add {prID}
# List patch requests
ssh pr.pico.sh pr ls amolith/go-lunatask
```

See "How do Patch Requests work?" on [pr.pico.sh]'s home page for a more
complete example workflow.

[amolith/go-lunatask]: https://pr.pico.sh/r/amolith/go-lunatask
[pr.pico.sh]: https://pr.pico.sh

## License

AGPL-3.0-or-later
