Skip to content

Adding advanced example #116

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

Merged
merged 10 commits into from
Jul 29, 2019
Merged
Changes from 3 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
105 changes: 105 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
* [Get events from a repository](#get-events-from-a-repository)
* [Get events from an issue](#get-events-from-an-issue)
* [Get a single event](#get-a-single-event])
* [Advanced](#advanced)
* [Migrating blog comments to github issues](#migrating-blog-comments-to-github-issues)

----------

Expand Down Expand Up @@ -496,3 +498,106 @@ Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue
```powershell
Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -EventID 1
```

----------

### Advanced

#### Migrating blog comments to github issues

I used this module to migrate my blog comments from Disqus to Github Issues. I'm using Utterances App to display the Github Issues on each blog posts. [See this blog post for more details](https://lazywinadmin.com/2019/04/moving_blog_comments.html)

```powershell
$GithubSplat = @{
OwnerName = 'lazywinadmin'
RepositoryName = 'lazywinadmin.github.io'
}
$BlogUrl = 'https://lazywinadmin.com'

# Retrieve existing issues
$issues = Get-GitHubIssue @githubsplat

# Process each threads with their comments
$BlogPosts |
Sort-Object name -Descending |
ForEach-Object -Process{

# Capture current blog thread
$BlogPost = $_

# Issue Title, replace the first / and
# remove the html at the end of the name
$IssueTitle = $BlogPost.name -replace '^\/' -replace '\.html'

# lookup for existing issue
$IssueObject = $issues|
Where-Object -filterscript {$_.title -eq $IssueTitle}

if(-not $IssueObject)
{
# Build Header of the post
$IssueHeader = $BlogPost.group.ThreadTitle |
select-object -first 1

# Define blog post link
$BlogPostLink = "$($BlogUrl)$($BlogPost.name)"

# Define body of the issue
$Body = @"
# $IssueHeader

[$BlogPostLink]($BlogPostLink)

<!--
Imported via PowerShell on $(Get-Date -Format o)
-->
"@
# Create an issue
$IssueObject = New-GitHubIssue @githubsplat `
-Title $IssueTitle `
-Body $body `
-Label 'blog comments'
}

# Sort comment by createdAt
$BlogPost.group|
Where-Object {$_.isspam -like '*false*'} |
Sort-Object createdAt |
ForEach-Object{

# Current comment
$CurrenComment = $_

# Author update
# we replace my post author name :)
$AuthorName = $($CurrenComment.AuthorName)
switch ($AuthorName)
{
'Xavier C' {$AuthorName='Francois-Xavier Cat'}
default {}
}

# Define body of the comment
$CommentBody = @"

## **Author**: $AuthorName
**Posted on**: ``$($CurrenComment.createdAt)``
$($CurrenComment.message)

<!--
Imported via PowerShell on $(Get-Date -Format o)
Json_original_message:
$($CurrenComment|Select-Object -ExcludeProperty raw|convertTo-Json)
-->
"@
# Create Comment
New-GitHubComment @githubsplat `
-Issue $IssueObject.number `
-Body $CommentBody
}
# Close issue
Update-GitHubIssue @githubsplat `
-Issue $IssueObject.number `
-State Closed
}
```