Gitea automation functions
parent
62e8afebb8
commit
8447b6009a
@ -0,0 +1,47 @@
|
||||
$apiurl=$args[0]
|
||||
$apitoken=$args[1]
|
||||
$filename=$args[2]
|
||||
$filepath=$args[3]
|
||||
|
||||
|
||||
Write-Host "apiurl: $apiurl"
|
||||
Write-Host "apitoken: $apitoken"
|
||||
Write-Host "filename: $filename"
|
||||
Write-Host "filepath: $filepath"
|
||||
|
||||
|
||||
# Load the required .NET assemblies
|
||||
Add-Type -AssemblyName System.Net.Http
|
||||
|
||||
# Create Object and Load the required .NET assemblies
|
||||
$httpClient = New-Object System.Net.Http.HttpClient
|
||||
|
||||
# $url = 'https://git.zinchuk.xyz/api/v1/repos/yuriy/TestRepo/releases/22/assets'
|
||||
# $fileName = 'TestFile58.exe'
|
||||
# $token = '2cf4a54d941'
|
||||
|
||||
$headers = @{
|
||||
'accept' = 'application/json'
|
||||
'Content-Type' = 'multipart/form-data'
|
||||
}
|
||||
|
||||
# $filePath = "C:\Users\yuriy\Syncthing\Git\TestREpo\test.exe"
|
||||
$fileBytes = [System.IO.File]::ReadAllBytes($filePath)
|
||||
$fileStream = [System.IO.MemoryStream]::new($fileBytes)
|
||||
|
||||
$httpClient = [System.Net.Http.HttpClient]::new()
|
||||
$httpClient.DefaultRequestHeaders.Add('Authorization', "Bearer $apitoken")
|
||||
|
||||
$multipartFormData = New-Object System.Net.Http.MultipartFormDataContent
|
||||
$fileContent = New-Object System.Net.Http.StreamContent -ArgumentList $fileStream
|
||||
$fileContent.Headers.ContentDisposition = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue -ArgumentList "form-data"
|
||||
$fileContent.Headers.ContentDisposition.Name = "attachment"
|
||||
$fileContent.Headers.ContentDisposition.FileName = $fileName
|
||||
# $fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("text/plain")
|
||||
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/x-msdownload")
|
||||
$multipartFormData.Add($fileContent)
|
||||
|
||||
$response = $httpClient.PostAsync($apiurl, $multipartFormData).Result
|
||||
$responseContent = $response.Content.ReadAsStringAsync().Result
|
||||
|
||||
Write-Output $responseContent
|
@ -0,0 +1,62 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Create a new release on on a Gitea site using the Gitea API
|
||||
|
||||
.DESCRIPTION
|
||||
The Add-Numbers function takes two integer parameters, $Number1 and $Number2,
|
||||
and returns the sum of those two numbers.
|
||||
|
||||
.PARAMETER APIURL
|
||||
The Repo Releases API URL of the Gitea site, including the API Key.
|
||||
Example: "https://gitea.example.com/api/v1/repos/yuriy/TESTREPO/releases?token=aaabbbcccdd"
|
||||
|
||||
.PARAMETER ReleaseName
|
||||
Name for the release that will be created
|
||||
|
||||
.PARAMETER ReleaseTag
|
||||
Tag for the release that will be created
|
||||
|
||||
.PARAMETER ReleaseBody
|
||||
Body Text for the release that will be created
|
||||
|
||||
.EXAMPLE
|
||||
Gitea-CreateRelease.ps1 "https://gitea.example.com/api/v1/repos/yuriy/TESTREPO/releases?token=aaabbbcccdd" "1.0" "1.0" "Initial Release"
|
||||
|
||||
.NOTES
|
||||
This function was created as an example for a PowerShell documentation demonstration.
|
||||
|
||||
.LINK
|
||||
https://example.com/powershell-functions
|
||||
#>
|
||||
|
||||
|
||||
$APIURL=$args[0]
|
||||
$ReleaseName=$args[1]
|
||||
$ReleaseTag=$args[2]
|
||||
$ReleaseBody=$args[3]
|
||||
|
||||
<#
|
||||
Write-Host "APIURL: $APIURL"
|
||||
Write-Host "ReleaseTag: $ReleaseTag"
|
||||
Write-Host "ReleaseName: $ReleaseName"
|
||||
Write-Host "ReleaseBody: $ReleaseBody"
|
||||
#>
|
||||
|
||||
$headers = @{
|
||||
"accept" = "application/json"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
$body = @{
|
||||
"body" = "${ReleaseBody}"
|
||||
"draft" = $false
|
||||
"name" = "${ReleaseTag}"
|
||||
"prerelease" = $false
|
||||
"tag_name" = "${ReleaseTag}"
|
||||
# "target_commitish" = "string"
|
||||
} | ConvertTo-Json
|
||||
|
||||
# Write-Host "body: " $body
|
||||
|
||||
$Result = Invoke-RestMethod -Uri $APIURL -Method Post -Headers $headers -Body $body
|
||||
|
||||
Write-Host $Result
|
@ -0,0 +1,63 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Adds two numbers and returns the result.
|
||||
|
||||
.DESCRIPTION
|
||||
The Add-Numbers function takes two integer parameters, $Number1 and $Number2,
|
||||
and returns the sum of those two numbers.
|
||||
|
||||
.PARAMETER Number1
|
||||
The first number to add.
|
||||
|
||||
.PARAMETER Number2
|
||||
The second number to add.
|
||||
|
||||
.EXAMPLE
|
||||
$sum = Add-Numbers -Number1 5 -Number2 10
|
||||
Write-Host "The sum is: $sum"
|
||||
|
||||
.NOTES
|
||||
This function was created as an example for a PowerShell documentation demonstration.
|
||||
|
||||
.LINK
|
||||
https://example.com/powershell-functions
|
||||
#>
|
||||
|
||||
|
||||
$APIURL=$args[0]
|
||||
$ReleaseName=$args[1]
|
||||
$ReleaseTag=$args[2]
|
||||
$ReleaseBody=$args[3]
|
||||
|
||||
|
||||
function CreateRelease {
|
||||
param (
|
||||
[string]$APIURL,
|
||||
[string]$ReleaseName,
|
||||
[string]$ReleaseID,
|
||||
[string]$ReleaseBody,
|
||||
)
|
||||
|
||||
$headers = @{
|
||||
"accept" = "application/json"
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
$body = @{
|
||||
"body" = "${ReleaseBody}"
|
||||
"draft" = $false
|
||||
"name" = "${ReleaseTag}"
|
||||
"prerelease" = $false
|
||||
"tag_name" = "${ReleaseTag}"
|
||||
"target_commitish" = "string"
|
||||
} | ConvertTo-Json
|
||||
|
||||
# Write-Host "body: " $body
|
||||
|
||||
$Result = Invoke-RestMethod -Uri $APIURL -Method Post -Headers $headers -Body $body
|
||||
|
||||
Write-Host $Result
|
||||
}
|
||||
|
||||
|
||||
|
||||
Write-FullName -FirstName "John" -LastName "Doe"
|
@ -0,0 +1,98 @@
|
||||
; https://www.autohotkey.com/boards/viewtopic.php?t=112391
|
||||
|
||||
; Usage:
|
||||
; cred := CredRead("CREDENTIALNAME", NewlineInPassword := 1)
|
||||
; Username := cred.username
|
||||
; Password := cred.password
|
||||
|
||||
; msgbox % cred.username
|
||||
; msgbox % cred.password
|
||||
|
||||
|
||||
; Functions
|
||||
;------------------------------------------------
|
||||
CredWrite(name, username, password)
|
||||
{
|
||||
VarSetCapacity(cred, 24 + A_PtrSize * 7, 0)
|
||||
cbPassword := StrLen(password)*2
|
||||
NumPut(1 , cred, 4+A_PtrSize*0, "UInt") ; Type = CRED_TYPE_GENERIC
|
||||
NumPut(&name , cred, 8+A_PtrSize*0, "Ptr") ; TargetName = name
|
||||
NumPut(cbPassword, cred, 16+A_PtrSize*2, "UInt") ; CredentialBlobSize
|
||||
NumPut(&password , cred, 16+A_PtrSize*3, "UInt") ; CredentialBlob
|
||||
NumPut(3 , cred, 16+A_PtrSize*4, "UInt") ; Persist = CRED_PERSIST_ENTERPRISE (roam across domain)
|
||||
NumPut(&username , cred, 24+A_PtrSize*6, "Ptr") ; UserName
|
||||
return DllCall("Advapi32.dll\CredWriteW"
|
||||
, "Ptr", &cred ; [in] PCREDENTIALW Credential
|
||||
, "UInt", 0 ; [in] DWORD Flags
|
||||
, "UInt") ; BOOL
|
||||
}
|
||||
|
||||
CredDelete(name)
|
||||
{
|
||||
return DllCall("Advapi32.dll\CredDeleteW"
|
||||
, "WStr", name ; [in] LPCWSTR TargetName
|
||||
, "UInt", 1 ; [in] DWORD Type,
|
||||
, "UInt", 0 ; [in] DWORD Flags
|
||||
, "UInt") ; BOOL
|
||||
}
|
||||
|
||||
CredRead(name,NewlineInUsername:=0, NewlineInPassword:=0)
|
||||
{
|
||||
DllCall("Advapi32.dll\CredReadW"
|
||||
, "Str", name ; [in] LPCWSTR TargetName
|
||||
, "UInt", 1 ; [in] DWORD Type = CRED_TYPE_GENERIC (https://learn.microsoft.com/en-us/windows/win32/api/wincred/ns-wincred-credentiala)
|
||||
, "UInt", 0 ; [in] DWORD Flags
|
||||
, "Ptr*", pCred ; [out] PCREDENTIALW *Credential
|
||||
, "UInt") ; BOOL
|
||||
if !pCred{
|
||||
; Username
|
||||
InputBox, Username, Input Username, Username not found. `nPlease Input Username for: `n--%name%--,,,,,,,,%Clipboard% ; , Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
|
||||
if(ErrorLevel)
|
||||
return
|
||||
|
||||
InputBox, Password, Input Password, Password not found. `nPlease Input Password for: `n--%name%--,,,,,,,,%Clipboard% ; , Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
|
||||
if(ErrorLevel)
|
||||
return
|
||||
|
||||
if !CredWrite(name, Username, Password)
|
||||
MsgBox failed to write cred
|
||||
else, { ; try reading the credential that was just saved
|
||||
DllCall("Advapi32.dll\CredReadW"
|
||||
, "Str", name ; [in] LPCWSTR TargetName
|
||||
, "UInt", 1 ; [in] DWORD Type = CRED_TYPE_GENERIC (https://learn.microsoft.com/en-us/windows/win32/api/wincred/ns-wincred-credentiala)
|
||||
, "UInt", 0 ; [in] DWORD Flags
|
||||
, "Ptr*", pCred ; [out] PCREDENTIALW *Credential
|
||||
, "UInt") ; BOOL
|
||||
}
|
||||
if !pCred{
|
||||
msgbox, Failed to read cred. after writing it to Credential Manager.
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
name := StrGet(NumGet(pCred + 8 + A_PtrSize * 0, "UPtr"), 256, "UTF-16")
|
||||
|
||||
; append new line to end if requested
|
||||
if(NewlineInUsername)
|
||||
username := StrGet(NumGet(pCred + 24 + A_PtrSize * 6, "UPtr"), 256, "UTF-16") . "`n"
|
||||
else,
|
||||
username := StrGet(NumGet(pCred + 24 + A_PtrSize * 6, "UPtr"), 256, "UTF-16")
|
||||
|
||||
len := NumGet(pCred + 16 + A_PtrSize * 2, "UInt")
|
||||
|
||||
; append new line to end if requested
|
||||
if(NewlineInPassword)
|
||||
password := StrGet(NumGet(pCred + 16 + A_PtrSize * 3, "UPtr"), len/2, "UTF-16") . "`n"
|
||||
else,
|
||||
password := StrGet(NumGet(pCred + 16 + A_PtrSize * 3, "UPtr"), len/2, "UTF-16")
|
||||
|
||||
|
||||
DllCall("Advapi32.dll\CredFree", "Ptr", pCred)
|
||||
return {"name": name, "username": username, "password": password}
|
||||
}
|
||||
|
||||
|
||||
; Misc
|
||||
;------------------------------------------------
|
||||
; Escape::ExitApp
|
Loading…
Reference in New Issue