Skip to content

Commit b27dfa1

Browse files
Added explicit comment_provider input to env0.plugin.yaml
1 parent 99d037d commit b27dfa1

File tree

2 files changed

+131
-83
lines changed

2 files changed

+131
-83
lines changed

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The Overmind plugin installs the Overmind CLI (and GitHub CLI) and executes one
1717
| `action` | The action to perform. Must be one of: `submit-plan`, `start-change`, `end-change`, `wait-for-simulation` | Yes |
1818
| `api_key` | Overmind API key for authentication. Must have the following scopes: `account:read`, `changes:write`, `config:write`, `request:receive`, `sources:read`, `source:write` | Yes |
1919
| `tags` | A comma-separated list of key=value tags to attach to the change (only used with `submit-plan` action) | No |
20-
| `post_comment` | Whether `wait-for-simulation` should post the Overmind markdown to GitHub PR or GitLab MR. Defaults to `true` when running against a PR/MR, otherwise `false`. Automatically detects GitHub or GitLab based on repository URL. | No |
20+
| `post_comment` | Whether `wait-for-simulation` should post the Overmind markdown to GitHub PR or GitLab MR. Defaults to `true` when running against a PR/MR, otherwise `false`. When `true`, `comment_provider` must be set. | No |
21+
| `comment_provider` | Where `wait-for-simulation` should post comments when `post_comment=true`. Must be one of: `github`, `gitlab`. | No |
2122

2223
## Usage
2324

@@ -90,7 +91,7 @@ deploy:
9091
9192
### Wait for Simulation (any step after Overmind run)
9293
93-
Fetch the latest Overmind simulation summary for the current env0 deployment and (optionally) comment on the matching GitHub pull request or GitLab merge request. By default the plugin posts comments whenever the deployment runs in the context of a PR/MR; set `post_comment: false` to skip commenting. The plugin automatically detects whether the repository is GitHub or GitLab based on the repository URL. When posting to GitHub, make sure `GH_TOKEN` is set. When posting to GitLab, make sure `GITLAB_TOKEN` is set.
94+
Fetch the latest Overmind simulation summary for the current env0 deployment and (optionally) comment on the matching GitHub pull request or GitLab merge request. By default the plugin posts comments whenever the deployment runs in the context of a PR/MR; set `post_comment: false` to skip commenting. When `post_comment=true`, you must set `comment_provider` to `github` or `gitlab`. When posting to GitHub, make sure `GH_TOKEN` is set. When posting to GitLab, make sure `GITLAB_TOKEN` is set.
9495

9596
```yaml
9697
version: 2
@@ -106,6 +107,38 @@ deploy:
106107
post_comment: false # optional override
107108
```
108109

110+
If you want to post a comment, set `comment_provider` explicitly:
111+
112+
```yaml
113+
version: 2
114+
deploy:
115+
steps:
116+
terraformApply:
117+
after:
118+
- name: Post Overmind Simulation (GitHub)
119+
use: https://github.com/your-org/env0-plugin
120+
inputs:
121+
action: wait-for-simulation
122+
api_key: ${OVERMIND_API_KEY}
123+
post_comment: true
124+
comment_provider: github
125+
```
126+
127+
```yaml
128+
version: 2
129+
deploy:
130+
steps:
131+
terraformApply:
132+
after:
133+
- name: Post Overmind Simulation (GitLab)
134+
use: https://github.com/your-org/env0-plugin
135+
inputs:
136+
action: wait-for-simulation
137+
api_key: ${OVERMIND_API_KEY}
138+
post_comment: true
139+
comment_provider: gitlab
140+
```
141+
109142
### Complete Example
110143

111144
Here's a complete example that uses the plan/change lifecycle actions:
@@ -192,7 +225,7 @@ deploy:
192225
4. Generate the token and copy it immediately—GitLab will not show it again.
193226
5. Store the token securely in env0 (for example as an environment variable or secret) and expose it to the plugin as `GITLAB_TOKEN`.
194227

195-
**Note**: The plugin automatically detects whether a repository is GitHub or GitLab based on the `ENV0_PR_SOURCE_REPOSITORY` environment variable. If the repository URL contains "gitlab", it will use GitLab API; otherwise, it will use GitHub CLI.
228+
**Note**: When `post_comment=true`, you must set `comment_provider` to `github` or `gitlab`.
196229
## Notes
197230

198231
- The plugin automatically detects the operating system and architecture to download the correct Overmind CLI binary.

env0.plugin.yaml

Lines changed: 95 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ inputs:
1414
description: "The Overmind instance to connect to (defaults to https://app.overmind.tech)"
1515
required: false
1616
post_comment:
17-
description: "Whether wait-for-simulation should post the Overmind markdown to the PR/MR. Defaults to true when ENV0_PR_NUMBER is set, otherwise false. Automatically detects GitHub or GitLab based on repository URL."
17+
description: "Whether wait-for-simulation should post the Overmind markdown to the PR/MR. Defaults to true when ENV0_PR_NUMBER is set, otherwise false. When true, comment_provider must be set."
18+
required: false
19+
comment_provider:
20+
description: "Where to post PR/MR comments when wait-for-simulation runs with post_comment=true. Must be one of: github, gitlab."
1821
required: false
1922
run:
2023
exec: |
@@ -344,86 +347,98 @@ run:
344347
echo "Error: ENV0_PR_SOURCE_REPOSITORY environment variable is not set but post_comment=true"
345348
exit 1
346349
fi
347-
348-
# Detect if this is a GitLab repository
349-
if echo "${ENV0_PR_SOURCE_REPOSITORY}" | grep -q "gitlab"; then
350-
# GitLab merge request
351-
if [ -z "${GITLAB_TOKEN}" ]; then
352-
echo "Error: GITLAB_TOKEN environment variable is not set but repository appears to be GitLab"
353-
exit 1
354-
fi
355-
356-
# Extract GitLab base URL and project path from repository string
357-
# ENV0_PR_SOURCE_REPOSITORY format: "group/project" or "https://gitlab.com/group/project" or "gitlab.com/group/project"
358-
REPO_STR="${ENV0_PR_SOURCE_REPOSITORY}"
359-
360-
# Remove protocol if present
361-
REPO_STR=$(echo "${REPO_STR}" | sed 's|^https\?://||')
362-
363-
# Extract host (default to gitlab.com if not specified)
364-
if echo "${REPO_STR}" | grep -q "/"; then
365-
GITLAB_HOST=$(echo "${REPO_STR}" | cut -d'/' -f1)
366-
PROJECT_PATH=$(echo "${REPO_STR}" | cut -d'/' -f2-)
367-
else
368-
# If no host, assume gitlab.com
369-
GITLAB_HOST="gitlab.com"
370-
PROJECT_PATH="${REPO_STR}"
371-
fi
372-
373-
# Ensure we have https:// prefix for API calls
374-
if [ "${GITLAB_HOST}" != "gitlab.com" ] && ! echo "${GITLAB_HOST}" | grep -q "^https\?://"; then
375-
GITLAB_BASE_URL="https://${GITLAB_HOST}"
376-
elif [ "${GITLAB_HOST}" = "gitlab.com" ]; then
377-
GITLAB_BASE_URL="https://gitlab.com"
378-
else
379-
GITLAB_BASE_URL="${GITLAB_HOST}"
380-
fi
381-
382-
# URL encode the project path (handle spaces and special chars)
383-
PROJECT_PATH_ENCODED=$(echo "${PROJECT_PATH}" | sed 's|/|%2F|g' | sed 's| |%20|g')
384-
385-
MR_IID="${ENV0_PR_NUMBER}"
386-
API_URL="${GITLAB_BASE_URL}/api/v4/projects/${PROJECT_PATH_ENCODED}/merge_requests/${MR_IID}/notes"
387-
388-
echo "Posting simulation results to GitLab MR ${PROJECT_PATH}!${MR_IID}..."
389-
390-
# Create JSON payload file using jq
391-
JSON_PAYLOAD_FILE=$(mktemp)
392-
jq -n --rawfile body "${MARKDOWN_FILE}" '{body: $body}' > "${JSON_PAYLOAD_FILE}"
393-
394-
# Post comment using curl
395-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
396-
-H "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
397-
-H "Content-Type: application/json" \
398-
--data-binary "@${JSON_PAYLOAD_FILE}" \
399-
"${API_URL}")
400-
401-
# Clean up JSON payload file
402-
rm -f "${JSON_PAYLOAD_FILE}"
403-
404-
if [ "${HTTP_CODE}" -ge 200 ] && [ "${HTTP_CODE}" -lt 300 ]; then
405-
echo "✓ Simulation results posted to GitLab MR"
406-
else
407-
echo "Error: Failed to post comment to GitLab MR (HTTP ${HTTP_CODE})"
408-
exit 1
409-
fi
410-
else
411-
# GitHub pull request
412-
if [ -z "${GH_BINARY}" ] || [ ! -x "${GH_BINARY}" ]; then
413-
echo "Error: GitHub CLI was not installed correctly"
414-
exit 1
415-
fi
416-
417-
if ! "${GH_BINARY}" auth status >/dev/null 2>&1; then
418-
echo "Warning: GitHub CLI authentication not detected. Ensure GH_TOKEN is configured."
419-
fi
420-
421-
echo "Posting simulation results to ${ENV0_PR_SOURCE_REPOSITORY}#${ENV0_PR_NUMBER}..."
422-
"${GH_BINARY}" pr comment "${ENV0_PR_NUMBER}" \
423-
--repo "${ENV0_PR_SOURCE_REPOSITORY}" \
424-
--body-file "${MARKDOWN_FILE}"
425-
echo "✓ Simulation results posted to GitHub PR"
350+
351+
comment_provider=$(echo "${inputs.comment_provider}" | tr '[:upper:]' '[:lower:]')
352+
if [ -z "${comment_provider}" ]; then
353+
echo "Error: comment_provider input must be set to 'github' or 'gitlab' when post_comment=true"
354+
exit 1
426355
fi
356+
357+
case "${comment_provider}" in
358+
gitlab)
359+
# GitLab merge request
360+
if [ -z "${GITLAB_TOKEN}" ]; then
361+
echo "Error: GITLAB_TOKEN environment variable is not set but comment_provider=gitlab"
362+
exit 1
363+
fi
364+
365+
# Extract GitLab base URL and project path from repository string
366+
# ENV0_PR_SOURCE_REPOSITORY format: "group/project" or "https://gitlab.com/group/project" or "gitlab.com/group/project"
367+
REPO_STR="${ENV0_PR_SOURCE_REPOSITORY}"
368+
369+
# Remove protocol if present
370+
REPO_STR=$(echo "${REPO_STR}" | sed 's|^https\?://||')
371+
372+
# Extract host (default to gitlab.com if not specified)
373+
if echo "${REPO_STR}" | grep -q "/"; then
374+
GITLAB_HOST=$(echo "${REPO_STR}" | cut -d'/' -f1)
375+
PROJECT_PATH=$(echo "${REPO_STR}" | cut -d'/' -f2-)
376+
else
377+
# If no host, assume gitlab.com
378+
GITLAB_HOST="gitlab.com"
379+
PROJECT_PATH="${REPO_STR}"
380+
fi
381+
382+
# Ensure we have https:// prefix for API calls
383+
if [ "${GITLAB_HOST}" != "gitlab.com" ] && ! echo "${GITLAB_HOST}" | grep -q "^https\?://"; then
384+
GITLAB_BASE_URL="https://${GITLAB_HOST}"
385+
elif [ "${GITLAB_HOST}" = "gitlab.com" ]; then
386+
GITLAB_BASE_URL="https://gitlab.com"
387+
else
388+
GITLAB_BASE_URL="${GITLAB_HOST}"
389+
fi
390+
391+
# URL encode the project path (handle spaces and special chars)
392+
PROJECT_PATH_ENCODED=$(echo "${PROJECT_PATH}" | sed 's|/|%2F|g' | sed 's| |%20|g')
393+
394+
MR_IID="${ENV0_PR_NUMBER}"
395+
API_URL="${GITLAB_BASE_URL}/api/v4/projects/${PROJECT_PATH_ENCODED}/merge_requests/${MR_IID}/notes"
396+
397+
echo "Posting simulation results to GitLab MR ${PROJECT_PATH}!${MR_IID}..."
398+
399+
# Create JSON payload file using jq
400+
JSON_PAYLOAD_FILE=$(mktemp)
401+
jq -n --rawfile body "${MARKDOWN_FILE}" '{body: $body}' > "${JSON_PAYLOAD_FILE}"
402+
403+
# Post comment using curl
404+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
405+
-H "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
406+
-H "Content-Type: application/json" \
407+
--data-binary "@${JSON_PAYLOAD_FILE}" \
408+
"${API_URL}")
409+
410+
# Clean up JSON payload file
411+
rm -f "${JSON_PAYLOAD_FILE}"
412+
413+
if [ "${HTTP_CODE}" -ge 200 ] && [ "${HTTP_CODE}" -lt 300 ]; then
414+
echo "✓ Simulation results posted to GitLab MR"
415+
else
416+
echo "Error: Failed to post comment to GitLab MR (HTTP ${HTTP_CODE})"
417+
exit 1
418+
fi
419+
;;
420+
github)
421+
# GitHub pull request
422+
if [ -z "${GH_BINARY}" ] || [ ! -x "${GH_BINARY}" ]; then
423+
echo "Error: GitHub CLI was not installed correctly"
424+
exit 1
425+
fi
426+
427+
if ! "${GH_BINARY}" auth status >/dev/null 2>&1; then
428+
echo "Warning: GitHub CLI authentication not detected. Ensure GH_TOKEN is configured."
429+
fi
430+
431+
echo "Posting simulation results to ${ENV0_PR_SOURCE_REPOSITORY}#${ENV0_PR_NUMBER}..."
432+
"${GH_BINARY}" pr comment "${ENV0_PR_NUMBER}" \
433+
--repo "${ENV0_PR_SOURCE_REPOSITORY}" \
434+
--body-file "${MARKDOWN_FILE}"
435+
echo "✓ Simulation results posted to GitHub PR"
436+
;;
437+
*)
438+
echo "Error: comment_provider input must be 'github' or 'gitlab' when post_comment=true"
439+
exit 1
440+
;;
441+
esac
427442
else
428443
if [ -n "${ENV0_PR_NUMBER}" ]; then
429444
echo "Skipping comment because post_comment=false."

0 commit comments

Comments
 (0)