Skip to content

Commit

Permalink
Merge pull request #86 from icefoganalytics/elcc-26/navigation-enhanc…
Browse files Browse the repository at this point in the history
…ement

ELCC26: Navigation Enhancement
  • Loading branch information
klondikemarlen authored Oct 4, 2024
2 parents e20109e + e2a14a8 commit e296e38
Show file tree
Hide file tree
Showing 15 changed files with 811 additions and 92 deletions.
11 changes: 11 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require_relative "./jira_api"
require_relative "./pull-request-editor"

class DevHelper
# Support dashes in command names
Expand All @@ -9,6 +10,7 @@ class DevHelper
"branch-from" => :branch_from,
"description-from" => :description_from,
"check-types" => :check_types,
"edit-pr" => :edit_pr,
}
METHOD_TO_COMMAND = COMMAND_TO_METHOD.invert

Expand Down Expand Up @@ -198,6 +200,15 @@ class DevHelper
puts description
end

##
# Edits the description of a pull request.
# Example:
# dev edit-pr https://github.com/icefoganalytics/travel-authorization/pull/218
def edit_pr(pull_request_url, *args, **kwargs)
PullRequestEditor.edit_pull_request_description(pull_request_url, *args, **kwargs)
exit(0)
end

def bash_completions
completions =
public_methods(false)
Expand Down
78 changes: 78 additions & 0 deletions bin/pull-request-editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require "tempfile"
require "open3"

##
# Supports fetching and editing PR descriptions from a full GitHub PR URL using SSH and GitHub CLI.
#
# Example usage:
# - PullRequestEditor.edit_pull_request_description('https://github.com/icefoganalytics/travel-authorization/pull/218')
class PullRequestEditor
# Edits the pull request description using GitHub CLI and VS Code
def self.edit_pull_request_description(pull_request_url)
if ENV["GITHUB_TOKEN"].nil?
puts "\nPlease set the GITHUB_TOKEN environment variable."
exit(1)
end

repo, pull_request_number = extract_repo_and_pull_request_number(pull_request_url)

pull_request_body = fetch_pull_request_body(repo, pull_request_number)

tmp_dir = File.join(Dir.home, "tmp")
Dir.mkdir(tmp_dir) unless Dir.exist?(tmp_dir)

Tempfile.create(["pull_request_description_#{pull_request_number}", ".md"], tmp_dir) do |file|
file.write(pull_request_body)
file.flush

system("code --wait #{file.path}")

updated_pull_request_body = File.read(file.path)

if updated_pull_request_body.strip != pull_request_body.strip
update_pull_request_body(repo, pull_request_number, file.path)
else
puts "No changes made to the PR description."
end
end
end

private

# Extracts the repository name and PR number from a full GitHub PR URL
def self.extract_repo_and_pull_request_number(pull_request_url)
match_data = pull_request_url.match(%r{github.com/([^/]+)/([^/]+)/pull/(\d+)})
repo = "#{match_data[1]}/#{match_data[2]}"
pull_request_number = match_data[3]
[repo, pull_request_number]
end

# Fetches the PR body using the GitHub CLI
def self.fetch_pull_request_body(repo, pull_request_number)
command = "gh pr view #{pull_request_number} --repo #{repo} --json body --jq .body"
puts "running: #{command}"
stdout, stderr, status = Open3.capture3(command)

if status.success?
stdout.strip
else
puts "Error fetching PR description: #{stderr}"
exit(1)
end
end

# Updates the PR body using the GitHub CLI
def self.update_pull_request_body(repo, pull_request_number, new_body_file_path)
command =
"gh pr edit #{pull_request_number} --repo #{repo} --body-file \"#{new_body_file_path}\""
puts "running: #{command}"
stdout, stderr, status = Open3.capture3(command)

if status.success?
puts "stdout: #{stdout}"
puts "PR description updated successfully."
else
puts "Error updating PR description: #{stderr}"
end
end
end
12 changes: 10 additions & 2 deletions web/eslint.config.js → web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://github.com/typescript-eslint/typescript-eslint/issues/251
export default {
module.exports = {
root: true,
env: {
browser: true,
Expand All @@ -23,5 +23,13 @@ export default {
sourceType: "module",
},
plugins: ["vue", "@typescript-eslint"],
rules: {},
rules: {
// Override/add rules' settings here
"vue/valid-v-slot": [
"error",
{
allowModifiers: true,
},
],
},
}
110 changes: 110 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@auth0/auth0-vue": "^2.0.0",
"@mdi/font": "^7.1.96",
"@vueuse/router": "^11.1.0",
"apexcharts": "^3.37.1",
"axios": "^1.3.3",
"lodash": "^4.17.21",
Expand Down
10 changes: 4 additions & 6 deletions web/src/api/funding-submission-line-jsons-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ export type FundingSubmissionLineJson = {
values: string
createdAt: string
updatedAt: string
}

export type FundingSubmissionLineJsonAsDetailed = Omit<FundingSubmissionLineJson, "values"> & {
// Virtual Attributes
lines: FundingLineValue[]
}

export type FundingSubmissionLineJsonAsIndex = Omit<FundingSubmissionLineJson, "values"> & {
lines: FundingLineValue[]
}
export type FundingSubmissionLineJsonAsIndex = Omit<FundingSubmissionLineJson, "values">
export type FundingSubmissionLineJsonAsDetailed = Omit<FundingSubmissionLineJson, "values">

export type FundingSubmissionLineJsonWhereOptions = {
centreId?: number
Expand Down Expand Up @@ -74,7 +72,7 @@ export const fundingSubmissionLineJsonsApi = {
},
async update(
fundingSubmissionLineJsonId: number,
attributes: any
attributes: Partial<FundingSubmissionLineJson>
): Promise<{ fundingSubmissionLineJson: FundingSubmissionLineJsonAsDetailed }> {
const { data } = await http.patch(
`/api/funding-submission-line-jsons/${fundingSubmissionLineJsonId}`,
Expand Down
Loading

0 comments on commit e296e38

Please sign in to comment.