main 970d248e5f07 cached
8 files
14.2 KB
3.6k tokens
1 symbols
1 requests
Download .txt
Repository: protontypes/continuous-reforestation
Branch: main
Commit: 970d248e5f07
Files: 8
Total size: 14.2 KB

Directory structure:
gitextract_bh9j322k/

├── .github/
│   └── workflows/
│       ├── linter.yml
│       ├── pull_request.yml
│       └── push.yml
├── Dockerfile
├── LICENSE
├── README.md
├── action.yml
└── planttree.py

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/workflows/linter.yml
================================================
name: Lint

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - uses: psf/black@master


================================================
FILE: .github/workflows/pull_request.yml
================================================
name: Example Integration on Pull Request
on: 
  pull_request_target:
    branches:
      - main
    types:
      - closed
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Plant a Tree
        if: github.event.pull_request.merged == true
        id: planttree
        uses: protontypes/continuous-reforestation@main
        with:
        # Enter your API variables below
            apikey: ${{ secrets.raaskey }}
            enterpriseid: "cd7cedcd"
            user: ${{ github.actor }}
            treecount: 5
            projectid: "14442771" # This projectid can be used to have your trees planted where they are needed the most.
            production: "false"

      - name: Response of digitalhumani.com RaaS API
        run: |
            echo "${{ steps.planttree.outputs.response }}"
            echo "${{ steps.planttree.outputs.plantedTrees }}"


================================================
FILE: .github/workflows/push.yml
================================================
name: Plant a tree on every push to main
on:
  push:
    branches:
      - main
jobs:
  plantrees:
    runs-on: ubuntu-latest
    steps:
      - name: Plant a Tree
        id: planttrees
        uses: protontypes/continuous-reforestation@main
        with:
        # Enter your API variables below
            apikey: ${{ secrets.raaskey }}
            enterpriseid: "cd7cedcd"
            user: ${{ github.actor }}
            treecount: 1
            projectid: "14442771" # This projectid can be used to have your trees planted where they are needed the most, so this is a great ID to use by default when making the API call. 
            production: "false"

      - name: Response of digitalhumani.com RaaS API
        run: |
            echo "${{ steps.planttrees.outputs.response }}"
            echo "${{ steps.planttrees.outputs.plantedTrees }}"


================================================
FILE: Dockerfile
================================================
FROM python:3-slim AS builder
ADD . /app
WORKDIR /app

# We are installing a dependency here directly into our app source dir
RUN pip install --target=/app requests

# A distroless container image with Python and some basics like SSL certificates
# https://github.com/GoogleContainerTools/distroless
FROM gcr.io/distroless/python3-debian10
COPY --from=builder /app /app
WORKDIR /app
ENV PYTHONPATH /app
CMD ["/app/planttree.py"]


================================================
FILE: LICENSE
================================================

The MIT License (MIT)

Copyright (c) 2018 protontypes and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


================================================
FILE: README.md
================================================
# Continuous Reforestation
**Make tree planting a part of your daily workflow. :deciduous_tree:** 

[<img src="logo.svg" align="right" width="250">](https://github.com/protontypes/continuous-reforestation)
A GitHub Action for planting trees within your development workflow using the Reforestation as a Service (RaaS) API developed by [DigitalHumani](https://digitalhumani.com/). 

Planting trees is an easy way to make a difference in the fight against climate change. Every tree helps to bind CO2 as long as it grows and creates living space for wildlife. Automating the process gives you total control of where, when and how much you want to contribute while saving you the fuss of doing the whole process manually. By using the RaaS API, you or your project can plant trees in a transparent way by exposing the API calls and related statistics. The RaaS API is completely free of charge. You only pay for the trees (1 $ each) directly to the reforestation organization. Find more information on this project read our [blog post](https://protontypes.eu/blog/2021/03/25/continuous-reforestation/). <br>  <br>
[![Actions Status](https://github.com/protontypes/continuous-reforestation/workflows/Lint/badge.svg)](https://github.com/jacobtomlinson/protontypes/continuous-reforestation/actions)
[![Actions Status](https://github.com/protontypes/continuous-reforestation/workflows/Integration%20Test/badge.svg)](https://github.com/protontypes/continuous-reforestation/actions)
[![](https://badgen.net/badge/icon/Community%20Chat/green?icon=gitter&label)](https://gitter.im/protontypes/community)

## Use cases
Plant trees on ...
* pull requests (and/or push, ...).
* failed or successful tests.
* the very first contribution to an open source project.
* a new release, a milestone, or a closed issue.
* a scheduled event (i.e. once per week).
* the carbon footprint of your digital products after deployment.

See more possible trigger events [here](https://docs.github.com/en/actions/reference/events-that-trigger-workflows).

## Usage

1. 🏁 To get started, you need an account with DigitalHumani RaaS. Since they are currently in the early stages, you have to contact them to get an account. Send them an email [here](https://digitalhumani.com/#contact). You also receive the API key value corresponding for your enterprise ID. This is your secret authentication key. **Do not add your API key to your workfile yaml file**.

2. ✂️ Copy the example worflow to `<your_git_repository>/.github/workflow/integration.yaml` and change the variables in the workflow to your data. Set the `production` variable to `false` to test your implementation within the sandboxed development API. Push your script to GitHub and check the GitHub Action tab of your project. If you use GitHub Action for the first time, activate it when prompted.

3. 📈 An open dashboard is provided to ensure a high level of transparency. This is currently under development and will show additional details. For this purpose visit:
``
https://digitalhumani.com/dashboard/<enterpriseid>
``

4. 🗝️ Add your authentication key as a secret in your repository `Settings` -> `Secrets` -> `New Repository Secret`: Name: `RAASKEY`, Value: `<your API key>`. You can also add it as an organization wide secret in the setting of your organization.

5. 🌱 Verify the number of trees planted in the dashboard development statistics. Set the `production` variable to `true` and push this commit. You now have left the development environment and started planting trees. From now on every configured trigger will continuously request to plant trees. At the end of each month you will be asked to confirm your requested amount of trees.

To see a list of all supported reforestation projects and more details on the RaaS API read the [documentation of DigitalHumani](https://digitalhumani.com/docs/#appendixlist-of-projects).

**Disclaimer:** Even though this workflow automates the request to plant trees, the planting process itself remains manual labour by the reforestation organisations. They are also the people who write your invoice. Due to the amount of work it requires to write these invoices, DigitalHumani accumulates your plant requests until you reach a certain number, depending on your chosen reforestation project, before issuing the order. Below are the least required amounts to receive a monthly invoice and actually plant trees. If you plant more, don't mind this disclaimer.

| Reforestation project | Necessary number of requested trees |
| --------------------- | ----------------------------------- |
| Chase Africa | 20 |
| Conserve Natural Forests | 20 |
| OneTreePlanted | 1 |
| Sustainable Harvest International | 50 |
| TIST | 20 | 

### Example workflows

```yaml
name: Plant a tree on a successful merged pull request to your main branch
on: 
  pull_request_target:
    branches:
      - main
    types:
      - closed
jobs:
  planttrees:
    runs-on: ubuntu-latest
    steps:
      - name: Plant a Tree
        if: github.event.pull_request.merged == true
        id: planttrees
        uses: protontypes/continuous-reforestation@main
        with:
        # Enter your API variables below
            apikey: ${{ secrets.raaskey }}
            enterpriseid: "<your_enterprise_ID>"
            user: ${{ github.actor }}
            treecount: 1
            projectid: "14442771" # This projectid can be used to have your trees planted where they are needed the most.
            production: "true"

      - name: Response of digitalhumani.com RaaS API
        run: |
            echo "${{ steps.planttrees.outputs.response }}"
```

```yaml
name: Plant a tree on every push to main
on:
  push:
    branches:
      - main
jobs:
  planttrees:
    runs-on: ubuntu-latest
    steps:
      - name: Plant a Tree
        id: planttrees
        uses: protontypes/continuous-reforestation@main
        with:
        # Enter your API variables below
            apikey: ${{ secrets.raaskey }}
            enterpriseid: "<your_enterprise_ID"
            user: ${{ github.actor }}
            treecount: 1
            projectid: "14442771" # This projectid can be used to have your trees planted where they are needed the most, so this is a great ID to use by default when making the API call. 
            production: "true"

      - name: Response of digitalhumani.com RaaS API
        run: |
            echo "${{ steps.planttrees.outputs.response }}"
```
---
### Inputs

| Input            | Description                           |
|------------------|---------------------------------------|
| `apikey`         | Your API secret key to the digitalhumani.com RaaS API. |
| `enterpriseid`   | ID of your enterprise.                |
| `user`           | End user by whom the trees were planted. Default is your GitHub user name. |
| `projectid`      | ID of the reforestation project for where you want the trees to be planted.    |
| `treecount`      | Number of trees requested to plant per API call as integer. Every tree will create costs of $1 per tree. |
| `production`     | Set `true` for the production API or false for the development API. |

### Outputs

| Output           | Description                           |
|------------------|---------------------------------------|
| `response`       | JSON response of the RaaS API |


================================================
FILE: action.yml
================================================
name: "continuous-reforestation"
description: "Plant trees within your development workflow with digitalhumani.com"
author: "protontypes"
branding:
  icon: 'award'  
  color: 'green'

inputs:
  apikey:
    description: "The API key obtained from digitalhumani.com"
  enterpriseid:
    description: "Id of your enterprise. Example of an enterprise id: 11111111 (Enterprise Ids are 8 digits long)"
    required: true
  user:
    decription: "End user by whom the trees were planted"
    default: ${{ github.actor }}
  projectid:
    description: "Id of the reforestation project for where you want the trees to be planted. Example of an id: 93333333 (Project Ids are 8 digits long)"
    required: true
  treeCount:
    description: "Number of trees requested to plant. Example: 1"
    default: 1
  production:
    decription: "Use sandbox or production API"
    default: "false"
outputs:
  response:
    description: "JSON response of the RaaS API"
  plantedTrees:
    description: "Number of trees planted by the enterprise."
runs:
  using: "docker"
  image: "Dockerfile"


================================================
FILE: planttree.py
================================================
#!/usr/bin/python3
import os
import requests
from urllib.parse import urljoin
import posixpath
import json
import sys
import re


def main():
    # Variables set by the CI script
    enterprise_id = os.environ["INPUT_ENTERPRISEID"]
    project_id = os.environ["INPUT_PROJECTID"]
    user = os.environ["INPUT_USER"]
    treecount = int(os.environ["INPUT_TREECOUNT"])
    production = os.environ["INPUT_PRODUCTION"]
    api_key = os.environ["INPUT_APIKEY"]

    # REST API Parameters
    body_para = {
        "treeCount": treecount,
        "enterpriseId": enterprise_id,
        "projectId": project_id,
        "user": user,
    }
    headers = {"x-api-key": api_key}

    # Check of we run in development or production mode
    # Using the sandbox API does not require any API key
    if production == "true":
        print("Using production API")
        url = "https://api.digitalhumani.com/tree"
        url_numtrees = (
            "https://api.digitalhumani.com/enterprise/"
            + enterprise_id
            + "/treeCount?startDate=2010-03-01&endDate=2030-01-01"
        )

    else:
        print("Using sandbox API for development")
        url = "https://api-dev.digitalhumani.com/tree"
        url_numtrees = (
            "https://api-dev.digitalhumani.com/enterprise/"
            + enterprise_id
            + "/treeCount?startDate=2010-03-01&endDate=2030-01-01"
        )

    # run the RaaS requests for planting trees and getting tree count
    r = requests.post(url, json=body_para, headers=headers)
    r_numtrees = requests.get(url_numtrees, headers=headers)

    # put the response into a dictionary
    response = json.loads(r.text)
    response_alltrees = json.loads(r_numtrees.text)
    response_alltrees = str(response_alltrees)
    num_alltrees = re.findall("[0-9]+", response_alltrees)
    plantedTrees = num_alltrees[0]

    # create a simple human readable response message
    if r.status_code == requests.codes.ok:
        print(
            "Request successful\n"
            + str(response["user"])
            + " planted "
            + str(response["treeCount"])
            + " tree(s). "
            + "Find more information on dashboard: "
            + "https://digitalhumani.com/dashboard/"
            + str(enterprise_id)
            + ".html\n"
            + plantedTrees
            + " were now planted in total."
        )
    else:
        print("Something went wrong. \n Your error code is: " + str(r.status_code))
        sys.exit(1)

    # return the dict to the CI script for following data processing
    print(f"::set-output name=response::{response}")
    print(f"::set-output name=response::{plantedTrees}")


if __name__ == "__main__":
    main()
Download .txt
gitextract_bh9j322k/

├── .github/
│   └── workflows/
│       ├── linter.yml
│       ├── pull_request.yml
│       └── push.yml
├── Dockerfile
├── LICENSE
├── README.md
├── action.yml
└── planttree.py
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: planttree.py
  function main (line 11) | def main():
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (15K chars).
[
  {
    "path": ".github/workflows/linter.yml",
    "chars": 193,
    "preview": "name: Lint\n\non: [push, pull_request]\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout"
  },
  {
    "path": ".github/workflows/pull_request.yml",
    "chars": 877,
    "preview": "name: Example Integration on Pull Request\non: \n  pull_request_target:\n    branches:\n      - main\n    types:\n      - clos"
  },
  {
    "path": ".github/workflows/push.yml",
    "chars": 855,
    "preview": "name: Plant a tree on every push to main\non:\n  push:\n    branches:\n      - main\njobs:\n  plantrees:\n    runs-on: ubuntu-l"
  },
  {
    "path": "Dockerfile",
    "chars": 429,
    "preview": "FROM python:3-slim AS builder\nADD . /app\nWORKDIR /app\n\n# We are installing a dependency here directly into our app sourc"
  },
  {
    "path": "LICENSE",
    "chars": 1096,
    "preview": "\nThe MIT License (MIT)\n\nCopyright (c) 2018 protontypes and contributors\n\nPermission is hereby granted, free of charge, t"
  },
  {
    "path": "README.md",
    "chars": 7312,
    "preview": "# Continuous Reforestation\n**Make tree planting a part of your daily workflow. :deciduous_tree:** \n\n[<img src=\"logo.svg\""
  },
  {
    "path": "action.yml",
    "chars": 1071,
    "preview": "name: \"continuous-reforestation\"\ndescription: \"Plant trees within your development workflow with digitalhumani.com\"\nauth"
  },
  {
    "path": "planttree.py",
    "chars": 2711,
    "preview": "#!/usr/bin/python3\nimport os\nimport requests\nfrom urllib.parse import urljoin\nimport posixpath\nimport json\nimport sys\nim"
  }
]

About this extraction

This page contains the full source code of the protontypes/continuous-reforestation GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (14.2 KB), approximately 3.6k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!