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

Pre-fill suggested New File 'name' and 'content' with Query Params #16556

Merged
merged 4 commits into from
Jul 29, 2021

Conversation

coolaj86
Copy link
Contributor

@coolaj86 coolaj86 commented Jul 27, 2021

Re: #16398

Use the same GET as the "New File" link, as seen here:

Screen Shot 2021-07-27 at 7 00 32 PM

And allow 3rd-party frontends to append ?filename=x&value=y to pre-populate the form:

Screen Shot 2021-07-27 at 7 01 19 PM

See also: Screen Capture Demo.

Pre-Fill New File Name & Contents w/ Query Params

If you'd like to open the New File page with suggested name and contents,
you can do so with the filename and value query parameters (just like GitHub):

GET /{{org}}/{{repo}}/_new/{{filepath}}
    ?filename={{filename}}
    &value={{content}}

For example:

GET https://git.example.com/johndoe/bliss/_new/articles/
    ?filename=hello-world.md
    &value=Hello%2C%20World!

This mirrors the documented behavior of Github, and fixes the known bug. Gist will also have this feature soon.

For Integration with File Templates

This allows you to use File Templating tools such as Bliss - which allows you to create blog articles, with FrontMatter, for Static Site blogs - acting as a de facto frontend for such platforms.

Test Binary

# Install Go
curl -sS https://webinstall.dev/golang | bash
# Clone Repo and Build
git clone https://github.com/coolaj86/gitea

pushd ./gitea

git checkout bliss

TAGS="bindata sqlite sqlite_unlock_notify" make build

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 27, 2021
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Jul 27, 2021
@lafriks lafriks added this to the 1.16.0 milestone Jul 27, 2021
@lunny
Copy link
Member

lunny commented Jul 27, 2021

Re: #16398

Pre-Fill New File Name & Contents w/ Query Params

If you'd like to create a new file with a given name and contents,
you can do so with query parameters:

GET /{{org}}/{{repo}}/_new/{{filepath}}
    ?filename={{filename}}
    &value={{content}}

For example:

GET https://git.example.com/johndoe/bliss/_new/articles/
    ?filename=hello-world.md
    &value=Hello%2C%20World!

To create or update a file, GET is not a suitable method.

@techknowlogick
Copy link
Member

To create or update a file, GET is not a suitable method.

@lunny this won't create the file, it will only pre-fill the textarea to suggest content. The user will need to hit "Submit" to do a POST and then the file will be created.

modules/context/context.go Outdated Show resolved Hide resolved
@coolaj86 coolaj86 changed the title Add query params for pre-defined filename and content Pre-fill suggested New File 'name' and 'content' with Query Params Jul 27, 2021
routers/web/repo/editor.go Outdated Show resolved Hide resolved
routers/web/repo/editor.go Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 28, 2021
@6543
Copy link
Member

6543 commented Jul 28, 2021

I still think we should have a ctx.Query who do action on query of url directly but this is not the scope of this pull

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 28, 2021
@codecov-commenter

This comment has been minimized.

modules/context/context.go Outdated Show resolved Hide resolved
@6543
Copy link
Member

6543 commented Jul 28, 2021

@coolaj86 did revert your comment since we should do this in #16562 :)

Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to hold you back but ...

@6543
Copy link
Member

6543 commented Jul 28, 2021

... it works all right beside you have to edit the filename box in UI to enable the Commit Changes button :/

beside that it's good to go

@coolaj86
Copy link
Contributor Author

@6543 It looks like you already pushed a commit to revert it?

I see "1 change requested", but I don't see what change is request.

@coolaj86 coolaj86 force-pushed the bliss branch 2 times, most recently from 6ed3869 to 841a68b Compare July 28, 2021 19:28
@6543 6543 merged commit b9a0e33 into go-gitea:main Jul 29, 2021
@6543
Copy link
Member

6543 commented Jul 29, 2021

@coolaj86 happy blogging :)

AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 10, 2021
…o-gitea#16556)

* feature: add (GitHub-style) querystrings for pre-filling new file content

* docs: add query parameters for new files
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants