-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve list templates and fix failing tests due to bugfixes #1277
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6f953e
Improve list templates and fix failing tests due to bugfixes
vanstee 61a34ba
Add alias info command now that alias list just prints names
vanstee fae96f7
Clean up left over templates and unify output
vanstee 78b697f
Fix rule template tests
vanstee 2bf520a
Fix tests for bundle info template changes
vanstee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
defmodule Cog.Commands.Alias.Info do | ||
use Cog.Command.GenCommand.Base, | ||
bundle: Cog.Util.Misc.embedded_bundle, | ||
name: "alias-info" | ||
|
||
alias Cog.Models.User | ||
alias Cog.Queries | ||
alias Cog.Repo | ||
|
||
require Cog.Commands.Helpers, as: Helpers | ||
|
||
@description "Shows a specific alias" | ||
|
||
@arguments "<alias-name>" | ||
|
||
@examples """ | ||
Showing a specific alias: | ||
|
||
alias info user:my-awesome-alias | ||
""" | ||
|
||
@output_description "Returns a serialized alias" | ||
|
||
@output_example """ | ||
[ | ||
{ | ||
"visibility": "user", | ||
"pipeline": "echo \\\"My Awesome Alias\\\"", | ||
"name": "my-awesome-alias" | ||
} | ||
] | ||
""" | ||
|
||
rule "when command is #{Cog.Util.Misc.embedded_bundle}:alias-info allow" | ||
|
||
def handle_message(req = %{args: [name]}, state) when is_binary(name) do | ||
user_id = req.user["id"] | ||
|
||
result = case find_alias(name, %User{id: user_id}) do | ||
{:ok, alias} -> | ||
{:ok, "alias-info", Helpers.jsonify(alias)} | ||
error -> | ||
error | ||
end | ||
|
||
case result do | ||
{:ok, template, data} -> | ||
{:reply, req.reply_to, template, data, state} | ||
{:error, err} -> | ||
{:error, req.reply_to, Helpers.error(err), state} | ||
end | ||
end | ||
|
||
def handle_message(req = %{args: []}, state), | ||
do: {:error, req.reply_to, Helpers.error({:not_enough_args, 1}), state} | ||
def handle_message(req, state), | ||
do: {:error, req.reply_to, Helpers.error({:too_many_args, 1}), state} | ||
|
||
def find_alias(full_name, user) do | ||
query = case full_name do | ||
"site:" <> name -> | ||
Queries.Alias.site_alias_by_name(name) | ||
"user:" <> name -> | ||
Queries.Alias.user_alias_by_name(user, name) | ||
name -> | ||
Queries.Alias.user_alias_by_name(user, name) | ||
end | ||
|
||
case Repo.one(query) do | ||
nil -> | ||
{:error, :not_found} | ||
alias -> | ||
{:ok, alias} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
~each var=$results~ | ||
**Name:** ~$item.visibility~:~$item.name~ | ||
**Pipeline:** `~$item.pipeline~` | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
~each var=$results as=bundle~ | ||
**ID:** ~$bundle.id~ | ||
**Name:** ~$bundle.name~ | ||
**Relay Groups:** ~if cond=$bundle.relay_groups empty?~Unassigned~end~~join var=$bundle.relay_groups with=", "~~$item.name~~end~ | ||
**Versions:** ~join var=$bundle.versions with=", "~~$item.version~~end~ | ||
~if cond=$bundle.incompatible_versions not_empty?~ | ||
**Incompatible Versions:** ~join var=$bundle.incompatible_versions with=", "~~$item.version~~end~ | ||
~end~ | ||
**Version Enabled:** ~if cond=$bundle.enabled_version bound?~~$bundle.enabled_version.version~~end~~if cond=$bundle.enabled_version not_bound?~Disabled~end~ | ||
**Relay Groups:** ~if cond=$bundle.relay_groups empty?~Unassigned~end~~join var=$bundle.relay_groups with=", "~~$item.name~~end~ | ||
~if cond=$bundle.incompatible_versions not_empty?~**Incompatible Versions:** ~join var=$bundle.incompatible_versions with=", "~~$item.version~~end~~end~ | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
~if cond=length($results) == 1~ | ||
**ID**: ~$results[0].id~ | ||
**Bundle**: ~$results[0].bundle~ | ||
**Name**: ~$results[0].name~ | ||
~end~ | ||
~if cond=length($results) > 1~ | ||
| Bundle | Name | ID | | ||
|--------|------|----| | ||
~each var=$results~ | ||
|~$item.bundle~|~$item.name~|~$item.id~| | ||
~end~ | ||
~each var=$results as=permission~ | ||
**Name:** ~$permission.bundle~:~$permission.name~ | ||
**ID:** ~$permission.id~ | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
~each var=$results~ | ||
~attachment color="gray"~ | ||
**Name:** ~$item.name~ | ||
**Bundle:** ~$item.bundle~ | ||
~$item.bundle~:~$item.name~ | ||
~end~ | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
~each var=$results as=role~ | ||
~$role.name~ | ||
|
||
~if cond=$role.permissions not_empty?~ | ||
~attachment color="blue"~ | ||
~$role.name~ (~count var=$role.permissions~ permissions) | ||
~end~ | ||
~end~ | ||
|
||
~if cond=$role.permissions empty?~ | ||
~attachment color="gray"~ | ||
~$role.name~ (0 permissions) | ||
~end~ | ||
~end~ | ||
|
||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
~if cond=length($results) == 1~ | ||
**ID**: ~$results[0].id~ | ||
**Command**: ~$results[0].command_name~ | ||
**Rule**: ~$results[0].rule~ | ||
~end~ | ||
~if cond=length($results) > 1~ | ||
| Command | Rule | ID | | ||
|---------|------|----| | ||
~each var=$results~|~$item.command_name~|~$item.rule~|~$item.id~| | ||
~end~ | ||
~each var=$results as=rule~ | ||
**ID:** ~$rule.id~ | ||
**Rule:** | ||
|
||
``` | ||
~$rule.rule~ | ||
``` | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
~each var=$results as=rule~ | ||
~attachment color="gray"~ | ||
**Command:** ~$rule.command~ | ||
**ID:** ~$rule.id~ | ||
**Rule:** | ||
|
||
``` | ||
~$rule.rule~ | ||
``` | ||
|
||
~end~ | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
~each var=$results~ | ||
Created trigger '~$item.id~' | ||
Created trigger '~$item.name~' | ||
~end~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
~if cond=length($results) == 1~ | ||
**ID**: ~$results[0].id~ | ||
**Name**: ~$results[0].name~ | ||
**Description**: ~$results[0].description~ | ||
**Enabled?**: ~$results[0].enabled~ | ||
**Pipeline**: `~$results[0].pipeline~` | ||
**As User**: ~$results[0].as_user~ | ||
**Timeout (sec)**: ~$results[0].timeout_sec~ | ||
**Invocation URL**: ~$results[0].invocation_url~ | ||
~end~ | ||
~if cond=length($results) > 1~ | ||
| ID | Name | Description | Enabled? | Pipeline | As User | Timeout | Invocation URL | | ||
|----|------|-------------|----------|----------|---------|---------|----------------| | ||
~each var=$results~|~$item.id~|~$item.name~|~if cond=$item.description bound?~~$item.description~~end~|~$item.enabled~|`~$item.pipeline~`|~if cond=$item.as_user~~$item.as_user~~end~|~$item.timeout_sec~|~$item.invocation_url~| | ||
~end~ | ||
~each var=$results as=trigger~ | ||
**Name:** ~$trigger.name~ | ||
**ID:** ~$trigger.id~ | ||
**Description:** ~$trigger.description~ | ||
**Status:** ~if cond=$trigger.enabled == true~Enabled~end~~if cond=$trigger.enabled == false~Disabled~end~ | ||
**Pipeline:** `~$trigger.pipeline~` | ||
**As User:** ~$trigger.as_user~ | ||
**Timeout:** ~$trigger.timeout_sec~ second~if cond=$trigger.timeout_sec > 1~s~end~ | ||
**Invocation URL:** ~$trigger.invocation_url~ | ||
~end~ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpeck Wasn't sure what this did. Let me know if we need to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed with @mpeck that this can be removed.