Skip to content

Commit

Permalink
Merge 9cdb41e into 6624525
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Dec 27, 2021
2 parents 6624525 + 9cdb41e commit ea27b4b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 30 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'Max width of a column'
required: false
default: '1000'
col_max_words:
description: 'Max number of words per line in a column'
required: false
default: '6'
output:
description: 'Path to the output file'
required: false
Expand All @@ -20,7 +24,7 @@ runs:
steps:
- run: |
curl -sf https://gobinaries.com/github.com/tj-actions/auto-doc@1.1.5 | PREFIX=. sh
./auto-doc --action="${{ inputs.action }}" --output="${{ inputs.output }}" --colMaxWidth="${{ inputs.col_max_width }}"
./auto-doc --action="${{ inputs.action }}" --output="${{ inputs.output }}" --colMaxWidth="${{ inputs.col_max_width }}" --colMaxWords="${{ inputs.col_max_words }}"
rm -f ./auto-doc
shell: bash
branding:
Expand Down
55 changes: 52 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var outputAutoDocEnd = fmt.Sprintf(AutoDocEnd, "OUTPUT")
var actionFileName string
var outputFileName string
var colMaxWidth string
var colMaxWords string

type Input struct {
Description string `yaml:"description"`
Expand Down Expand Up @@ -75,6 +76,11 @@ func (a *Action) renderOutput() error {
return err
}

maxWords, err := strconv.Atoi(colMaxWords)
if err != nil {
return err
}

inputTableOutput := &strings.Builder{}

if len(a.Inputs) > 0 {
Expand All @@ -101,7 +107,7 @@ func (a *Action) renderOutput() error {
if len(a.Inputs[key].Default) > 0 {
_default = fmt.Sprintf("`%s`", a.Inputs[key].Default)
}
row := []string{key, "string", strconv.FormatBool(a.Inputs[key].Required), _default, a.Inputs[key].Description}
row := []string{key, "string", strconv.FormatBool(a.Inputs[key].Required), _default, wordWrap(a.Inputs[key].Description, maxWords)}
inputTable.Append(row)
}

Expand Down Expand Up @@ -144,7 +150,7 @@ func (a *Action) renderOutput() error {

outputTable.SetColWidth(maxWidth)
for _, key := range keys {
row := []string{key, "string", a.Outputs[key].Description}
row := []string{key, "string", wordWrap(a.Outputs[key].Description, maxWords)}
outputTable.Append(row)
}

Expand Down Expand Up @@ -272,7 +278,13 @@ func init() {
&colMaxWidth,
"colMaxWidth",
"1000",
"Column max width",
"Max width of a column",
)
rootCmd.PersistentFlags().StringVar(
&colMaxWidth,
"colMaxWords",
"6",
"Max number of words per line in a column",
)
}

Expand Down Expand Up @@ -301,3 +313,40 @@ func replaceBytesInBetween(value []byte, startIndex int, endIndex int, new []byt
w += copy(t[w:], value[endIndex:])
return t[0:w]
}

func wordWrap(s string, limit int) string {
if strings.TrimSpace(s) == "" {
return s
}
// convert string to slice
strSlice := strings.Fields(s)
currentLimit := limit

var result string

for len(strSlice) >= 1 {
// convert slice/array back to string
// but insert <br> at specified limit

if len(strSlice) < currentLimit {
currentLimit = len(strSlice)
result = result + strings.Join(strSlice[:currentLimit], " ")
} else if currentLimit == limit {
result = result + strings.Join(strSlice[:currentLimit], " ") + "<br>"
} else {
result = result + strings.Join(strSlice[:currentLimit], " ")
}

// discard the elements that were copied over to result
strSlice = strSlice[currentLimit:]

// change the limit
// to cater for the last few words in
//
if len(strSlice) < currentLimit {
currentLimit = len(strSlice)
}

}
return result
}
50 changes: 25 additions & 25 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->

| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------|--------|----------|-----------------------|-------------------------------------------------------------------------------|
| base_sha | string | false | | Specify a base commit SHA on used for comparing changes |
| files | string | false | | Check for changes using only this list of files (Defaults to the entire repo) |
| path | string | false | | Specify a relative path under $GITHUB_WORKSPACE to locate the repository |
| separator | string | true | ` ` | Split character for array output |
| sha | string | true | `${{ github.sha }}` | Specify a current commit SHA used for comparing changes |
| token | string | true | `${{ github.token }}` | Github token or Repo Scoped Personal Access Token |
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------|--------|----------|-----------------------|-------------------------------------------------------------------------------------|
| base_sha | string | false | | Specify a base commit SHA used<br>for comparing changes |
| files | string | false | | Check for changes using only this<br>list of files (Defaults to the<br>entire repo) |
| path | string | false | | Specify a relative path under $GITHUB_WORKSPACE<br>to locate the repository |
| separator | string | true | ` ` | Split character for array output |
| sha | string | true | `${{ github.sha }}` | Specify a current commit SHA used<br>for comparing changes |
| token | string | true | `${{ github.token }}` | Github token or Repo Scoped Personal<br>Access Token |

<!-- AUTO-DOC-INPUT:END -->

## Outputs

<!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section -->

| OUTPUT | TYPE | DESCRIPTION |
|--------------------------------|--------|-----------------------------------------------------------------------------------|
| added_files | string | List of added files. |
| all_changed_and_modified_files | string | List of all changed files. |
| all_modified_files | string | List of all copied modified and added files. |
| any_changed | string | Return true only when any files provided using the files input have changed. |
| any_deleted | string | Return true only when any files provided using the files input have been deleted. |
| copied_files | string | List of copied files. |
| deleted_files | string | List of deleted files. |
| modified_files | string | List of modified files. |
| only_changed | string | Return true when all files provided using the files input have changed. |
| only_deleted | string | Return true when all files provided using the files input have been deleted. |
| other_deleted_files | string | Return list of deleted files not listed in the files input. |
| renamed_files | string | List of renamed files. |
| type_changed_files | string | List of files that had type changes. |
| unknown_files | string | List of unknown files. |
| unmerged_files | string | List of unmerged files. |
| OUTPUT | TYPE | DESCRIPTION |
|--------------------------------|--------|-----------------------------------------------------------------------------------------|
| added_files | string | List of added files. |
| all_changed_and_modified_files | string | List of all changed files. |
| all_modified_files | string | List of all copied modified and<br>added files. |
| any_changed | string | Return true only when any files<br>provided using the files input have<br>changed. |
| any_deleted | string | Return true only when any files<br>provided using the files input have<br>been deleted. |
| copied_files | string | List of copied files. |
| deleted_files | string | List of deleted files. |
| modified_files | string | List of modified files. |
| only_changed | string | Return true when all files provided<br>using the files input have changed.<br> |
| only_deleted | string | Return true when all files provided<br>using the files input have been<br>deleted. |
| other_deleted_files | string | Return list of deleted files not<br>listed in the files input. |
| renamed_files | string | List of renamed files. |
| type_changed_files | string | List of files that had type<br>changes. |
| unknown_files | string | List of unknown files. |
| unmerged_files | string | List of unmerged files. |

<!-- AUTO-DOC-OUTPUT:END -->
2 changes: 1 addition & 1 deletion test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
required: true
default: ${{ github.sha }}
base_sha:
description: 'Specify a base commit SHA on used for comparing changes'
description: 'Specify a base commit SHA used for comparing changes'
required: false
path:
description: 'Specify a relative path under $GITHUB_WORKSPACE to locate the repository'
Expand Down

0 comments on commit ea27b4b

Please sign in to comment.