Skip to content
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

Add comment without encapulate into code block when comment title is omited #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ static async System.Threading.Tasks.Task Main(string[] args)
}

string comment = string.Empty;
if (!string.IsNullOrEmpty(COMMENT_FROM_FILE) && !string.IsNullOrWhiteSpace(COMMENT_FROM_FILE))
if (!string.IsNullOrEmpty(COMMENT_FROM_FILE) && !string.IsNullOrWhiteSpace(COMMENT_FROM_FILE) && !string.IsNullOrWhiteSpace(COMMENT_TITLE))
{
string title = COMMENT_TITLE.ToString().Trim();
title = !string.IsNullOrEmpty(title) ? title : "Gitea Comment";
Console.WriteLine("Reading from file");
comment = $"## {title}\\n```text\\n"+System.IO.File.ReadAllText(COMMENT_FROM_FILE.ToString()).Trim().Replace(Environment.NewLine, "\\n")+"\\n```";
}
else if (!string.IsNullOrEmpty(COMMENT_FROM_FILE)
&& !string.IsNullOrWhiteSpace(COMMENT_FROM_FILE)
&& string.IsNullOrWhiteSpace(COMMENT_TITLE))
{
Console.WriteLine("Reading from file");
var file = await System.IO.File.ReadAllTextAsync(COMMENT_FROM_FILE);
comment = file.Trim().Replace(Environment.NewLine, @"\n");
}
else
{
Console.WriteLine("Reading from specified text");
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ steps:
status: [ failure ]
event: pull_request
```

Example reference providing Markdown comments from Marktdown files:

Do not specify the title so that the contents of the file are not
encapsulated within a code block.

```yml
steps:
- name: post-to-gitea-pr
image: tsakidev/giteacomment:latest
settings:
gitea_token:
from_secret: gitea_token
gitea_base_url: http://gitea.example.com
comment_from_file: "/path/to/file.md"
when:
status: [ failure ]
event: pull_request
```