Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Ready to run in production? Please [check our deployment guides](https://hexdocs
* Docs: https://hexdocs.pm/phoenix
* Forum: https://elixirforum.com/c/phoenix-forum
* Source: https://github.com/phoenixframework/phoenix

## Do some things
8 changes: 8 additions & 0 deletions commit_messages/successful_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#codellama
Here is the commit message generated based on the provided git diff:

"Update config for runtime environment
* Move config from config/dev.exs to config/runtime.exs
* Remove four_hours variable and replace with one_day variable
* Update cache_ttl value to one_day in blog module
* Update cache_ttl_long value to one_day in blog module"
7 changes: 7 additions & 0 deletions commit_messages/successful_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#codellama
Here's the generated commit message based on the provided GIT DIFF:

"Update configuration for production environment to use one day as cache ttl"

* config :blog, cache_ttl: four_hours -> one_day (variable = 4 * 60 * 60 * 1000)
* config :blog, cache_ttl_long: one_day -> one_day (variable = 24 * 60 * 60 * 1000)
23 changes: 23 additions & 0 deletions commit_messages/successful_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#codegemme

Here is the commit message based on the changes analyzed:

"Add config for long cache ttl and update cache ttl to use a new variable"

* `cache_ttl`: Removed from `config.exs` and added to `runtime.exs` as `four_hours` (value = 4 * 60 * 60 * 1000) -> `one_day` (value = 24 * 60 * 60 * 1000).
* `cache_ttl_long`: Added to `config.exs` as `one_day`.
* `blog` configuration: The cache TTL was updated from `four_hours` to `one_day`, and the long cache TTL was added.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch commit-hook-test
# Your branch is up to date with 'origin/commit-hook-test'.
#
# Changes to be committed:
# modified: config/config.exs
# modified: config/runtime.exs
#
# Untracked files:
# commit_messages/
#
24 changes: 24 additions & 0 deletions commit_messages/successful_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#codegemme

Here is the generated commit message:

"Update configuration for blog app"

* `cache_ttl` from 4 hours (variable = actual value) -> 1 day (variable = actual value) in config.exs
* `cache_ttl_long` from 1 day (variable = actual value) -> 24 hours (variable = actual value) in config.exs
* Added `four_hours` variable with actual value of 4 * 60 * 60 * 1000 in runtime.exs
* Added `one_day` variable with actual value of 24 * 60 * 60 * 1000 in runtime.exs

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch commit-hook-test
# Your branch is up to date with 'origin/commit-hook-test'.
#
# Changes to be committed:
# modified: config/config.exs
# modified: config/runtime.exs
#
# Untracked files:
# commit_messages/
#
22 changes: 22 additions & 0 deletions commit_messages/successful_5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# LLama 3.3

Commit Message:

"Move config from dev.exs to runtime.exs and change cache_ttl from 4 hours to 24 hours"

Changes:

* Moved config from `dev.exs` to `runtime.exs`.
* Changed `cache_ttl` from `(4 * 60 * 60 * 1000)` (4 hours) to `(24 * 60 * 60 * 1000)` (24 hours).
* Added `cache_ttl_long` set to `(24 * 60 * 60 * 1000)` (24 hours).

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch commit-hook-test
# Your branch is up to date with 'origin/commit-hook-test'.
#
# Changes to be committed:
# modified: config/config.exs
# modified: config/dev.exs
#
23 changes: 23 additions & 0 deletions commit_messages/successful_6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# llama 3.3

Here is the generated commit message based on the provided diff:
```
Move config from dev.exs to runtime.exs and change cache_ttl from 4 hours to 24 hours

Changes:
* Moved config from `dev.exs` to `runtime.exs`.
* Changed `cache_ttl` from `(4 * 60 * 60 * 1000)` (4 hours) to `(24 * 60 * 60 * 1000)` (24 hours).
* Added `cache_ttl_long` set to `(24 * 60 * 60 * 1000)` (24 hours).
```

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch commit-hook-test
# Your branch is up to date with 'origin/commit-hook-test'.
#
# Changes to be committed:
# new file: commit_messages/successful_5.txt
# modified: config/config.exs
# modified: config/dev.exs
#
23 changes: 23 additions & 0 deletions commit_messages/successful_7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# llama 3.3
Here is the generated commit message based on the provided diff:
```
Move config from dev.exs to runtime.exs and change cache_ttl from 4 hours to 24 hours

Changes:
* Moved config from `dev.exs` to `runtime.exs`.
* Changed `cache_ttl` from `(4 * 60 * 60 * 1000)` (4 hours) to `(24 * 60 * 60 * 1000)` (24 hours).
* Added `cache_ttl_long` set to `(24 * 60 * 60 * 1000)` (24 hours).
```

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch commit-hook-test
# Your branch is up to date with 'origin/commit-hook-test'.
#
# Changes to be committed:
# new file: commit_messages/successful_5.txt
# new file: commit_messages/successful_6.txt
# modified: config/config.exs
# modified: config/dev.exs
#
5 changes: 5 additions & 0 deletions commit_messages/successful_8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#CodeLlama:34B
Add commit message based on given diff.

* Move blog.cache_ttl from dev.exs to config.exs, changing value from
one_day (24 hours) to four_hours (4 hours)
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ config :phoenix, :json_library, Jason
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

four_hours = (4 * 60 * 60 * 1000)
one_day = (24 * 60 * 60 * 1000)

config :blog, cache_ttl: four_hours
config :blog, cache_ttl_long: one_day
3 changes: 2 additions & 1 deletion lib/blog/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Blog.Application do
# Start Finch
{Finch, name: Blog.Finch},
# Start the Endpoint (http/https)
BlogWeb.Endpoint
BlogWeb.Endpoint,
{Cachex, name: :blog_cache}
# Start a worker by calling: Blog.Worker.start_link(arg)
# {Blog.Worker, arg}
]
Expand Down
25 changes: 25 additions & 0 deletions lib/blog/cache.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Blog.Cache do
@moduledoc """
Simple cache implementation using Cachex with TTL support.
"""

@cache_name :blog_cache

def put(key, value, ttl \\ nil) do
ttl = ttl || Application.get_env(:blog, :cache_ttl)
Cachex.put(@cache_name, key, value, ttl: ttl)
value
end

def get(key) do
case Cachex.get(@cache_name, key) do
{:ok, nil} -> {:error, :not_found}
{:ok, value} -> {:ok, value}
{:error, _} -> {:error, :not_found}
end
end

def delete(key) do
Cachex.del(@cache_name, key)
end
end
108 changes: 108 additions & 0 deletions lib/blog/stories.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
defmodule Blog.Stories do
@moduledoc """
The Stories context.
"""

import Ecto.Query, warn: false
alias Blog.Repo

alias Blog.Stories.Story

@doc """
Returns the list of stories.

## Examples

iex> list_stories()
[%Story{}, ...]

"""
def list_stories do
Repo.all(Story)
end

def list_stories(user_id) do
Repo.all(from s in Story, where: s.user_id == ^user_id)
end

@doc """
Gets a single story.

Raises `Ecto.NoResultsError` if the Story does not exist.

## Examples

iex> get_story!(123)
%Story{}

iex> get_story!(456)
** (Ecto.NoResultsError)

"""
def get_story!(id, user_id), do: Repo.get_by!(Story, id: id, user_id: user_id)

@doc """
Creates a story.

## Examples

iex> create_story(%{field: value})
{:ok, %Story{}}

iex> create_story(%{field: bad_value})
{:error, %Ecto.Changeset{}}

"""
def create_story(attrs \\ %{}) do
%Story{}
|> Story.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a story.

## Examples

iex> update_story(story, %{field: new_value})
{:ok, %Story{}}

iex> update_story(story, %{field: bad_value})
{:error, %Ecto.Changeset{}}

"""
def update_story(%Story{} = story, attrs) do
story
|> Story.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a story.

## Examples

iex> delete_story(story)
{:ok, %Story{}}

iex> delete_story(story)
{:error, %Ecto.Changeset{}}

"""
def delete_story(%Story{} = story) do
Repo.delete(story)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking story changes.

## Examples

iex> change_story(story)
%Ecto.Changeset{data: %Story{}}

"""
def change_story(%Story{} = story, attrs \\ %{}) do
Story.changeset(story, attrs)
end
end
19 changes: 19 additions & 0 deletions lib/blog/stories/story.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Blog.Stories.Story do
use Ecto.Schema
import Ecto.Changeset

schema "stories" do
field :body, :string
field :title, :string
field :user_id, :id

timestamps()
end

@doc false
def changeset(story, attrs) do
story
|> cast(attrs, [:title, :body, :user_id])
|> validate_required([:title, :body, :user_id])
end
end
Loading